Skip to content

[bug] http fetch fails to send form with correct image encoding #4312

@evbo

Description

@evbo

Describe the bug

If you call the http form function to produce a Body that includes both a Byte array file the correct mime type isn't used and what gets uploaded is a unicode text file instead of an image.

Example:

Reproduction

Call the fetch api with a body created by Body.form(...) with an end result similar to:

{someKey: {file: byteArray, mime: 'image/png', fileName: 'aFile.png'}

Where "someKey" is what your server expects to be the key in the form containing the file and byteArray is an array of numbers, each number between (-128, 127).

An example byte array (in plain text) is attached (for the Tauri logo):
128x1282x

The file will be correctly uploaded, however it will simply be a text file, not binary (image) if in linux you run the command file -i img.png it will show a mime type of plain text.

As a control simply perform the upload specifying an absolute path to the image file:

{someKey: {file: 'path/to/file', mime: 'image/png', fileName: 'filename.png'}}

And this works great! So we know it is only an issue when supplying a byte array as file

Expected behavior

The file should have mime type of image/png

Platform and versions

Linux (Ubuntu 20.04, Centos 7, Windows 10)

[build-dependencies]
tauri-build = { version = "1.0.0-rc.12", features = [] }

[dependencies]
tauri = { version = "1.0.0-rc.14", features = ["fs-read-file", "fs-write-file", "http-all", "http-multipart", "shell-open"] }

Stack trace

No response

Additional context

I tried adding reqwest-client but that resulted in it completely not uploading at all with my server rejecting:

org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions