Skip to content

Support changing dataType for a binding in v4 #72

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
ejizba opened this issue Mar 31, 2023 · 6 comments
Open

Support changing dataType for a binding in v4 #72

ejizba opened this issue Mar 31, 2023 · 6 comments

Comments

@ejizba
Copy link
Contributor

ejizba commented Mar 31, 2023

v3 function.json content:

{
    "name": "myQueueItem",
    "type": "queueTrigger",
    "direction": "in",
    "queueName": "helloworldqueue",
    "connection": "storage_APPSETTING",
    "dataType": "binary"
}

v3 index.js content:

module.exports = async function (context, myQueueItem) {
    context.log('JavaScript queue trigger function processed work item', myQueueItem);
};

In v3 the type of myQueueItem changes based on the value of dataType. If you set dataType to binary, myQueueItem will be a Buffer. Otherwise, myQueueItem will either be a string or possibly a parsed object if the string was JSON.

In v4, we don't allow users to change myQueueItem to a Buffer type, which we should. This does not apply to http triggers, but probably applies to several other triggers/bindings other than storage queue.

@vsantele
Copy link

Is there any news on this issue? Or a way to help fix it?

@ejizba
Copy link
Contributor Author

ejizba commented May 31, 2023

No updates, but this is still planned to be fixed before we GA. For a workaround, either use the v3 model or use generics:

import { app, InvocationContext, trigger } from "@azure/functions";

export async function storageQueueTrigger1(queueItem: unknown, context: InvocationContext): Promise<void> {
    context.log(`Is it a buffer? ${Buffer.isBuffer(queueItem)}`);
}

app.generic('storageQueueTrigger1', {
    trigger: trigger.generic({
        type: 'queueTrigger',
        queueName: 'testqueue',
        connection: 'storage_APPSETTING',
        dataType: 'binary'
    }),
    handler: storageQueueTrigger1
});

@ejizba ejizba removed the GA blocker label Aug 10, 2023
@ejizba ejizba added P2 and removed v4 🚀 We no longer use this label since v4 is now the default model. labels Oct 10, 2023
@sinedied
Copy link
Member

Bumping into this, I have a storage extra input trying to load a PDF file, and I cannot get the blob content as a binary.

@ejizba is there a workaround when using the v4 extraInputs for setting the dataType?

@ejizba
Copy link
Contributor Author

ejizba commented Mar 28, 2024

This has been de-prioritized in favor of a feature that uses @azure/storage-blob sdk types, where basically we would give you a BlobClient as the trigger input or extra input and you can use the client to get the content however you want. @castrodd is working on a prototype now, related to #99 and #203

In the meantime, the only workaround for extra inputs is to use the sdk and create the blob client yourself. There is no workaround for trigger inputs. Actually, I already mentioned a workaround above using generics, that should still work for both.

@sinedied
Copy link
Member

Thanks for the details! I ended up using @azure/storage-blob but I like to try using any opportunity to reduce/simplify code 🙂 I'll have a look at generics, seems like a nice workaround.

@rohsyl
Copy link

rohsyl commented Jul 18, 2024

As its still not fixed yet you can use this workaround :

app.eventHub('LiveData', {
    connection: '...',
    eventHubName: 'messages/events',
    cardinality: 'many',
    consumerGroup: '%...%',
    handler: ...,
    dataType: 'binary',
} as any);

add the dataType and simply force cast as any and it works. it looks like it's just a typescript definition issue.

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

4 participants