Skip to content

Detect content-type during addFile #38

@sntran

Description

@sntran

Hi,

Currently I have a request stream and I pass that stream to node-cloudfiles' addFile as

cloudfile.addFile("container", "{remote: "fileName.ext", stream: readStream}, callback)

However, since the request stream has content-type set to application/octet-stream, it is saved as application/octet-stream in Rackspace.

From core.js:addFile:

addOptions = {
  method: 'PUT',
  client: this,
  upload: lstream,
  uri: this.storageUrl(container, options.remote),
  headers: options.headers || {}
};

if (options.headers && !options.headers['content-type']) {
  options.headers['content-type'] = mime.lookup(options.remote);
}

Understandably, it will only try to look up MIME type when options.headers is set, so for my above code to work, I would include a headers: {} in the options argument.

My question is, I'm not sure why it only tries to detect when options.headers is set. I, for one, would not want to do any thing with the request headers, yet still want the MIME to be look up immediately.

Would changing to the below in core.js:addFile cause any problem?

addOptions = {
  method: 'PUT',
  client: this,
  upload: lstream,
  uri: this.storageUrl(container, options.remote),
  headers: options.headers || {}
};

if (!addOptions.headers['content-type']) {
  addOptions.headers['content-type'] = mime.lookup(options.remote);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions