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

Unable to set contentType when uploading file using uploadFile #6192

Closed
csanghvi-stripe opened this issue Nov 14, 2019 · 5 comments
Closed
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)

Comments

@csanghvi-stripe
Copy link

csanghvi-stripe commented Nov 14, 2019

If i am uploading a file, there isnt a property to set the content type. File is then saved in blob storage with default applicaiton/octet mime type.

    const containerClient = blobServiceClient.getContainerClient(container)
    // const content = 'Hello world!'
    const blobName = 'newblob' + new Date().getTime()
    const blockBlobClient = containerClient.getBlockBlobClient(fileName)
    // const uploadBlobResponse = await blockBlobClient.upload(content, content.length)
    var options = {contentSettings:{contentType:'image/png'}}
    const uploadBlobResponse = await blockBlobClient.uploadFile(localFilePath, {
      blockSize: 4 * 1024 * 1024, // 4MB block size
      parallelism: 20, // 20 concurrency
      progress: (ev) => console.log(ev),
      options: options
    })

Edited: code formatting

@ramya-rao-a ramya-rao-a added Client This issue points to a problem in the data-plane of the library. Storage Storage Service (Queues, Blobs, Files) labels Nov 14, 2019
@ramya-rao-a ramya-rao-a added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Nov 14, 2019
@XiaoningLiu
Copy link
Member

@csanghvi Will take a look.

@ljian3377
Copy link
Member

ljian3377 commented Nov 19, 2019

@csanghvi
You can specify the content type with BlockBlobParallelUploadOptions.blobHTTPHeaders.blobContentType.

var options = {blobContentType:'image/png'}
const uploadBlobResponse = await blockBlobClient.uploadFile(localFilePath,
{blockSize: 4 * 1024 * 1024, parallelism: 20, onProgress: (ev) => console.log(ev),
blobHTTPHeaders: options})

@jeremymeng jeremymeng added the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Nov 21, 2019
@shivarajnaidu
Copy link

shivarajnaidu commented Feb 14, 2020

Not able to set content type.. it's by default getting saved as octane stream (Default) even though if I set the content type as image/png as below..

  const blockBlobClient = containerClient.getBlockBlobClient('myImag6.png', { blobHTTPHeaders: { blobContentType: 'image/png' } });

@ljian3377
Copy link
Member

Not able to set content type.. it's by default getting saved as octane stream (Default) even though if I set the content type as image/png as below..

  const blockBlobClient = containerClient.getBlockBlobClient('myImag6.png', { blobHTTPHeaders: { blobContentType: 'image/png' } });

@shivarajnaidu
The interface you used dosen't support additional parameters apart from the blobName.

public getBlockBlobClient(blobName: string): BlockBlobClient {}

Could you refer to the code I provided?

var options = {blobContentType:'image/png'}
const uploadBlobResponse = await blockBlobClient.uploadFile(localFilePath,
{blockSize: 4 * 1024 * 1024, parallelism: 20, onProgress: (ev) => console.log(ev),
blobHTTPHeaders: options})

Or are you asking for a way to save the setting for the blob?

@shivarajnaidu
Copy link

Thanks for the clarification @ljian3377

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

6 participants