Dio: Setting and sending the right content type of file.

Created on 10 Apr 2019  ·  4Comments  ·  Source: flutterchina/dio

Steps to Reproduce


I want to upload images or multiple different file types, like .pdf, .doc and .jpg

By default, the file type is mimetype: 'application/octet-stream'.
Even if I set contentType: ContentType('image', 'jpeg') in options, application/octet-stream gets saved as content-type.

How can I set the content type of the uploaded files automatically to the right content type.
All file upload plugins I have been using for web and mobile development, could get the right content type from the file and I did not need to set it manually.

Am I missing something?

Most helpful comment

 UploadFileInfo(file, fileName, contentType: ContentType('image', 'jpeg'))

All 4 comments

 UploadFileInfo(file, fileName, contentType: ContentType('image', 'jpeg'))

I used package:mime/mime.dart to get the mime type of the file and then inserted it into UploadFileInfo, like you suggested.

what is content type for pdf and documents

what is content type for pdf and documents

"application/pdf"

Was this page helpful?
0 / 5 - 0 ratings