Hello Alexandru BAU,
Thank you for posting your query here!
The reason why the content type changes when copying a file from one blob to another using extra outputs in Azure Functions is that the blob output binding does not automatically preserve the content type of the source file. Instead, it uses the default content type of application/octet-stream, unless you explicitly specify a different content type in the binding configuration. This is a known limitation of the blob output binding.
The solution to preserve the content type of the source file when copying a file from one blob to another using extra outputs in Azure Functions is to use the contentType property in the blob output binding configuration. This property allows you to specify the content type of the output blob, either as a static value or as a dynamic expression. For example, if you know that the source file is always a PDF document, you can set the contentType property to application/pdf, as shown in the following code snippet:
const blobOutput = output.storageBlob({
connection: 'DOCUMENTS_STORAGE',
path: 'documents/analyzed/analyzed-{queueTrigger}',
contentType: 'application/pdf' // specify the content type of the output blob
});
Alternatively, if you want to dynamically set the content type of the output blob based on the content type of the input blob, you can use the context.bindings object to access the input blob metadata, and use the contentType property of the input blob as the value of the contentType property of the output blob, as shown in the following code snippet:
const blobOutput = output.storageBlob({
connection: 'DOCUMENTS_STORAGE',
path: 'documents/analyzed/analyzed-{queueTrigger}',
contentType: context.bindings.blobInput.contentType // use the content type of the input blob as the content type of the output blob
});
By using the contentType property in the blob output binding configuration, you can ensure that the content type of the copied file is the same as the content type of the original file and avoid any issues with opening or processing the file.
Do let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.