Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uploadBlob with HTTP PUT corrupted #263

Open
giantslogik opened this issue Jul 2, 2024 · 2 comments
Open

uploadBlob with HTTP PUT corrupted #263

giantslogik opened this issue Jul 2, 2024 · 2 comments
Assignees

Comments

@giantslogik
Copy link

giantslogik commented Jul 2, 2024

Describe the bug
I'm replacing react-native-fetch-blob with this library. This library seems to force form-data when using the uploadBlob API. This results in a corrupted upload. (upload is to google cloud storage)

To Reproduce
const request = {
absoluteFilePath: filePath,
method: 'PUT',
mimeType: mimeType || 'application/octet-stream',
url,
onProgressWrap,
progressIntervalMilliseconds: 250,
};

const res = await BlobCourier.uploadBlob(request);

Expected behavior
File is uploaded correctly.

Actual behavior
The headers end up inside the uploaded file:
Screenshots
I opened the binary png file, in a text editor , as you can see its corrupt and the headers are in the uploaded file.
Screenshot 2024-07-02 at 2 27 30 PM

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@giantslogik giantslogik changed the title uploadBlob without form Data uploadBlob with HTTP PUT corrupted Jul 3, 2024
@edeckers edeckers self-assigned this Jul 4, 2024
@edeckers
Copy link
Owner

edeckers commented Jul 4, 2024

Hi @giantslogik thank you for reporting this problem, I'll try to take a closer look this weekend!

@giantslogik
Copy link
Author

@edeckers I believe google cloud storage and other PUT based uploads, should not be using form data.
I replaced the blob-courier code with the following:

  const localFile = await fetch(filePath);
  const blob = await localFile.blob();
 var xhr = new XMLHttpRequest();
    xhr.open('PUT', url, true);
    xhr.onload = function () {
      if (xhr.status >= 200 && xhr.status < 300) {
        ....
      } else {
      ....
      }
    };
    xhr.onerror = function () {
     ...
    };
    xhr.upload.onprogress =  function () {
     ...
    };
    xhr.setRequestHeader('Accept', 'application/json');
    xhr.setRequestHeader('Content-Type', mimeType || 'application/octet-stream');
    xhr.send(blob);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants