Skip to content

Blob bindings can't set ContentType and other properties #364

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

Open
buchizo opened this issue May 19, 2016 · 35 comments
Open

Blob bindings can't set ContentType and other properties #364

buchizo opened this issue May 19, 2016 · 35 comments

Comments

@buchizo
Copy link

buchizo commented May 19, 2016

The blob output binding feature set always application/octet-stream to ContentType property.
If possible, I would like to modified some blob properties.

And, Just now I don't found documents about some bindings.
Example, Blob output binding can use %rand-guid%. And file name placeholder can use {name} from input binding.

I want to know details about bindings.

@christopheranderson
Copy link
Contributor

This is definitely an issue. It would be helpful to know if you're trying to use C#/Node. Could just share a code sample with us?

We have a variety of ideas for how to make this smoother. We'd appreciate your input on how you'd like to set the Content Type, as well.

@buchizo
Copy link
Author

buchizo commented May 29, 2016

Example: https://gist.github.com/buchizo/2f8ac640a21cd78920eccbfd7e0d267d

If I use CloudBlockBlob, I can set ContentType property. But it's not easily.

@christopheranderson
Copy link
Contributor

Agreed that you shouldn't have to use CloudBlockBlob - we should aim to make this work cross language, which means using generic types.

@christopheranderson christopheranderson added this to the Next milestone Jun 2, 2016
@christopheranderson christopheranderson self-assigned this Jun 2, 2016
@christopheranderson
Copy link
Contributor

We should think through how we'd design this.

@christopheranderson
Copy link
Contributor

I think this is related to binding data improvements we've had in mind for node.

@mathewc
Copy link
Member

mathewc commented Jun 30, 2016

Another related issue here: #465. In general, we want to allow "object" bindings. I.e., allow a user to specify dataType: "object" in their binding metadata, which we translate to a JObject binding on the extension, with the extension handling the mapping from Blob/EventData => JObject, which can then be exposed to script.

@Adamsimsy
Copy link

Any progress on being able to configure the content/mimetype when the output type is "blob" in Azure functions?

@mathewc
Copy link
Member

mathewc commented Sep 3, 2016

Not yet - we'll get to it :)

@Adamsimsy
Copy link

Cool looking forward to it :D

@ricklove
Copy link

ricklove commented Jul 10, 2017

Found this after making my feature request in #1664.

There, I specified that I would like to be able to set properties to static values like this:

{
    "name": "outOutputBlob",
    "type": "blob",
    "direction": "out",
    "path": "{container}/{blob}",
    "connection": "AZURE_STORAGE_CONNECTION_STRING",
    "properties": {
        "cacheControl": "public, max-age 86400",
        "contentType": "application/json",
        "contentEncoding": "gzip"
    }
}

Maybe to set the value at runtime:

context.bindings.outputBlob = {data: '...'};
context.bindingsMetadata.outputBlob.properties = {contentType:'application/json'}; 

@AlejandroGil
Copy link

Is there any progress on this?

@paulbatum
Copy link
Member

No progress on this yet. Right now our main priority for JavaScript is getting the new out-of-proc model used in functions V2 to have feature and behavior parity with V1. Switching from Edge.js to a seperate node.exe process communicating over grpc is a pretty large change with a tail of bugs that will impact users trying to upgrade to V2 if not fixed.

@AlejandroGil
Copy link

AlejandroGil commented Mar 28, 2018

Thank you Paul,

I finally resolved it using Azure storage SDK:

var azure = require('azure-storage');
var streamifier = require('streamifier');

var options = {contentSettings:{contentType:'application/xml'}}
content_stream = streamifier.createReadStream("content");
var blobService = azure.createBlobService("DefaultEndpointsProtocol=https;AccountName=.....");
content_stream.pipe(blobService.createWriteStreamToBlockBlob(container, outputFileName, options, function(error, result, response){...}

@lucasmike
Copy link

any update on this issues?

@paulbatum
Copy link
Member

My comment above still reflects the current state.

@nemanjamil
Copy link

This is one of the solutions for upload image and set the adequate mime - content type
https://github.com/nemanjamil/azure-functions/blob/master/azure_upload_image.js

@mikhailshilkov
Copy link

mikhailshilkov commented Jun 25, 2019

This basically means that the example from the docs (repeated twice) doesn't work. For some files (e.g. text/html), it copies the contents but breaks the content type. For others (e.g. png), it breaks the content too: I got the encoding messed up and a "copy" file is twice as long.

Tested with these bindings:

{"disabled":false,"bindings":[
  {"authLevel":"anonymous","type":"httpTrigger","direction":"in","name":"req","route":"{name}"},
  {"type":"http","direction":"out","name":"response"},
  {"name":"original","type":"blob","direction":"in","path":"files/{name}","connection":"StorageConnectionStringKey"},
  {"name":"copy","type":"blob","direction":"out","path":"files/copy-{name}","connection":"StorageConnectionStringKey"}
]}

@forki
Copy link
Contributor

forki commented Oct 21, 2019

still not possible? that's a bummer

@shahedurrahman
Copy link

Is there any progress on this? Thanks

@eastonharvey
Copy link

Any updates on this? Would like to set properties on a Service Bus binding.

@matses
Copy link

matses commented Sep 7, 2020

any updates on this?

@alexanderomnix
Copy link

any update?

@SashiDareddy
Copy link

2021 and still waiting for this feature.

@invisibleaxm
Copy link

Any chance you we can get an update?

@NewFuture
Copy link

5 Years have passed!

@shanselman
Copy link

👀

@WestDiscGolf
Copy link

Just came across this issue. It also applied to the new isolated process model for C# as well. Any news?

@shanselman
Copy link

shanselman commented Jan 10, 2022 via email

@WestDiscGolf
Copy link

@shanselman thanks for sharing the link. The Blob bindings in the new isolated model don't give those options unfortunately. I guess the only option will be to inject a BlockBlobClient manually through DI and save it that way instead of an BlobOutput binding.

@WestDiscGolf
Copy link

WestDiscGolf commented Jan 10, 2022

What I ended up doing was not using the binding at all.

  1. Registering the BlobServiceClient in ConfigureServices
services.AddAzureClients(builder =>
        {
            builder.AddBlobServiceClient(hostContext.Configuration["AzureWebJobsStorage"]);
        });
  1. Injecting into the azure function, through dependency injection, a BlobServiceClient.

  2. In the timer function method getting a Blob Container Client.

var containerClient = _blobServiceClient.GetBlobContainerClient("my-blob-name");
  1. Creating a BlockBlobClient from the Container client.
var blockClient = containerClient.GetBlockBlobClient("blob-name.json");
  1. Writing the data to a stream and uploading it like @shanselman example.
Stream jsonStream = new MemoryStream();
await JsonSerializer.SerializeAsync(jsonStream, mydata, new JsonSerializerOptions() { WriteIndented = true });
jsonStream.Position = 0;
await blockClient.UploadAsync(jsonStream, new BlobHttpHeaders() { ContentType = "application/json" });

Hope this helps others.

@Guzzter
Copy link

Guzzter commented Jan 24, 2022

Thanks @shanselman for the always entertaining Youtube videos, this time about his Azure Friday Web API issue. Also thanks for the helpful pointers @WestDiscGolf!

I managed to brew my own Azure Function storing files with filename generation at runtime with Json content type. If you want to see how I did it: https://github.com/Guzzter/RatingViewerToJson

@elrondfeng
Copy link

is there a solution to this problem?

@gamecubate
Copy link

And this is why we switched to some other platform.

@mk7exe
Copy link

mk7exe commented Aug 18, 2023

Seriously! This is still an issue?! Wow! No update?

@RoryMcCrossan
Copy link

RoryMcCrossan commented Mar 15, 2024

Are you actually joking... 8 YEARS LATER and this has still not been adressed? The entire Azure blob storage offering is an inconsistent mess.

This is unbelieveable. My bar of expectation for you guys is on the floor, and here you are bringing shovels.

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