Set file content-type #552

Closed
opened 2017-01-03 18:24:25 +00:00 by retrospectacus · 4 comments
retrospectacus commented 2017-01-03 18:24:25 +00:00 (Migrated from github.com)

Is there any way to set a default content-type for files to be uploaded?
I require this to use AWS S3 pre-signed upload URLs.
I tried this but it has no effect on the PUT request headers.

onAfterAddingFile(fileItem: FileItem) {
        fileItem.method = "PUT";   // this works
        // neither of these lines has any effect.
        if (!fileItem.file.type)  fileItem.file.type = 'application/octet-stream';
        if (!fileItem['some'].type)  fileItem['some'].type = 'application/octet-stream';

When I choose e.g. an .SQL file the resultant PUT request does not send any content-type header.

I also tried adding a header to the fileItem's header array but this does not work as per https://github.com/valor-software/ng2-file-upload/blob/development/components/file-upload/file-uploader.class.ts#L341

Is there any way to set a default content-type for files to be uploaded? I require this to use AWS S3 pre-signed upload URLs. I tried this but it has no effect on the PUT request headers. ``` onAfterAddingFile(fileItem: FileItem) { fileItem.method = "PUT"; // this works // neither of these lines has any effect. if (!fileItem.file.type) fileItem.file.type = 'application/octet-stream'; if (!fileItem['some'].type) fileItem['some'].type = 'application/octet-stream'; ``` When I choose e.g. an .SQL file the resultant PUT request does not send any content-type header. I also tried adding a header to the fileItem's header array but this does not work as per https://github.com/valor-software/ng2-file-upload/blob/development/components/file-upload/file-uploader.class.ts#L341
hetzbr commented 2017-01-13 17:49:29 +00:00 (Migrated from github.com)

You can set the allowed mimeType:

this.uploader = new FileUploader({
allowedMimeType: ['application/octet-stream']
});

You can set the allowed mimeType: this.uploader = new FileUploader({ allowedMimeType: ['application/octet-stream'] });
retrospectacus commented 2017-01-16 02:41:15 +00:00 (Migrated from github.com)

Thanks for the reply but that is not what I am trying to do. All mime types are allowed. I want to set the file's mime type to octet stream if the file does not have any mime type otherwise detected.
When I override the uploader _xhrTransport with my PR, I can accomplish my goal by setting the content type header on the file if the mime type is blank.

Thanks for the reply but that is not what I am trying to do. All mime types are allowed. I want to set the file's mime type to octet stream if the file does not have any mime type otherwise detected. When I override the uploader _xhrTransport with my PR, I can accomplish my goal by setting the content type header on the file if the mime type is blank.
perrosen commented 2018-01-24 05:37:40 +00:00 (Migrated from github.com)

I had a similar problem. Mine was related to computer not recognising the mime type. I added the Content-Type header manually like so:

file.headers = [{name: 'Content-Type', value: mime.getType(this.currentFile.some.name)}];

Worked like a charm.

I had a similar problem. Mine was related to computer not recognising the mime type. I added the Content-Type header manually like so: file.headers = [{name: 'Content-Type', value: mime.getType(this.currentFile.some.name)}]; Worked like a charm.
crunchfactory commented 2018-07-26 19:57:41 +00:00 (Migrated from github.com)

Hi perrosen, where did you set the mime type at, specifically?

Hi perrosen, where did you set the mime type at, specifically?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#552