question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Developer set Content type header deleted if data is blob/file. (Caused by #1773)

See original GitHub issue

Describe the bug

I have a chunked file uploader, all data is to be sent as application/octet-stream in PUT in a binary stream. This worked in 0.19.2.

However, 0.20.0 fails because of code added under #1773 “Fixing overwrite Blob/File type as Content-Type in browser.”.

Line 21 lib/adapters/xhr.js:

    if (
      (utils.isBlob(requestData) || utils.isFile(requestData)) &&
      requestData.type
    ) {
      delete requestHeaders['Content-Type']; // Let the browser set it
    }

This “fix” now breaks my application as it assumes the browser knows best - it doesn’t. It also is semantically inaccurate to set the content type to something like image/jpeg when the data is 20MB chunk from the middle of a jpeg file - the data is NOT of content type image/jpeg.

The “fix” applied in #1773 appears to be fixing overwrite caused by setting of default content-type headers but this solution removes ANY control over the header by the developer when dealing with Blobs.

To Reproduce

Simply set content-type in a request where the payload is a blob.

Expected behavior

Axios should NOT delete the content type header set by the developer specifically on the request. The power to control this should remain with the calling code and not be dictated by the library.

Environment

  • Axios Version 0.20.0
  • Adapter XHR
  • Browser ALL
  • Browser Version ALL
  • Node.js Version n/a
  • OS: ALL (Linux, Windows, mac)

Additional context/Screenshots

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jasonsaaymancommented, Oct 13, 2020

I have merged as this makes sense to me that Axios should not dictate headers it seems a bit counterproductive or if we do try to sense a header we should at least allow overrides to work.

1reaction
adamdehavencommented, Sep 15, 2020

@Gerhut Any idea when this change will be reverted/fixed? I’d hate to have to revert to 0.19.x just for this one issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set Content-type of media files stored on Blob - Stack Overflow
This should work: var storageAccount = CloudStorageAccount.Parse("YOURCONNECTIONSTRING"); var blobClient = storageAccount.
Read more >
Manage properties and metadata for a blob with .NET
Learn how to set and retrieve system properties and store custom metadata on blobs in your Azure Storage account using the .
Read more >
react-native-fetch-blob - npm
To send a form data, the Content-Type header does not matter. When the body is an Array we will set proper content type...
Read more >
Reset Azure Blob Storage Content Type in .NET Core
My blog is using Azure Blob Storage to store images for posts, however, it went wrong these days when I am trying out...
Read more >
How to use Azure Blob Storage with ASP.NET Core Web API
NET Core to upload, download and delete files from your ... ContentType; // Create new BlobDto with blob data from variables return new ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found