sybrenstuvel / flickrapi

Python Flickr API implementation
https://stuvel.eu/flickrapi
Other
155 stars 33 forks source link

Prevent Error 5: Filetype was not recognised specifying the file exte… #128

Closed alitaker closed 3 years ago

alitaker commented 4 years ago

Prevent "Error 5: Filetype was not recognised" when uploading uncommon file types. Tested with .mts and .m2ts.

While the current flickrapi is failing with the above error, the html official uploader is working as expected, when uploading .mts and .m2ts files. I analyzed the HTTP log in the browser and noticed that the contet-type section of the actual file data was something like:

-----------------------------27598564016011352821359952635
Content-Disposition: form-data; name="photo"; filename="my_file.MTS"
Content-Type: video/vnd.dlna.mpeg-tts

Putting the extension in the filename (instead of "dummy name") did the trick. At this time the content-type does not seem required: the filename is probably triggering an auto resolution of the content-type by the Flickr servers

jim-easterbrook commented 4 years ago

Is there any reason not to use the actual filename?

params['photo'] = (os.path.basename(filename), fileobj)
alitaker commented 4 years ago

The reason is that the file name may contain special characters that may corrupt the process. Since the original code was using "dummy name", this is just a conservative way to improve it.

jim-easterbrook commented 4 years ago

Of course, I remember that change now.