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.
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
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.
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.
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
You can set the allowed mimeType:
this.uploader = new FileUploader({
allowedMimeType: ['application/octet-stream']
});
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.
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.
Hi perrosen, where did you set the mime type at, specifically?