Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.94k stars 441 forks source link

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

Open buchizo opened 8 years ago

buchizo commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

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

christopheranderson commented 8 years ago

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

christopheranderson commented 8 years ago

We should think through how we'd design this.

christopheranderson commented 8 years ago

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

mathewc commented 8 years ago

Another related issue here: https://github.com/Azure/azure-webjobs-sdk-script/issues/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 commented 8 years ago

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

mathewc commented 8 years ago

Not yet - we'll get to it :)

Adamsimsy commented 8 years ago

Cool looking forward to it :D

ricklove commented 7 years ago

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 commented 6 years ago

Is there any progress on this?

paulbatum commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

any update on this issues?

paulbatum commented 6 years ago

My comment above still reflects the current state.

nemanjamil commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

still not possible? that's a bummer

shahedurrahman commented 4 years ago

Is there any progress on this? Thanks

eastonharvey commented 4 years ago

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

matses commented 4 years ago

any updates on this?

alexanderomnix commented 3 years ago

any update?

SashiDareddy commented 3 years ago

2021 and still waiting for this feature.

invisibleaxm commented 3 years ago

Any chance you we can get an update?

NewFuture commented 3 years ago

5 Years have passed!

shanselman commented 2 years ago

👀

WestDiscGolf commented 2 years ago

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

shanselman commented 2 years ago

This is how Jeff Hollan solved it for me https://github.com/shanselman/azurefridayaggregator/pull/1/files

It's not clean, but it works. I would prefer that I be able to set the content type more readily in a single line.

On Sat, Jan 8, 2022 at 1:22 PM Adam Storr @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-functions-host/issues/364#issuecomment-1008157025, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAWTBDL24O5H3LCKAYLTLUVCTIHANCNFSM4CEKPBKA . You are receiving this because you commented.Message ID: @.***>

WestDiscGolf commented 2 years ago

@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 commented 2 years ago

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");
  2. 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 commented 2 years ago

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 commented 2 years ago

is there a solution to this problem?

gamecubate commented 1 year ago

And this is why we switched to some other platform.

mk7exe commented 1 year ago

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

RoryMcCrossan commented 8 months ago

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.