Skip to content

Support changing dataType for a binding in v4 #72

Open

Description

@ejizba

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.

Activity

  1. vsantele commented on May 29, 2023

    @vsantele

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

  2. ejizba commented on May 31, 2023

    @ejizba
    ContributorAuthor

    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
    });
  3. added and removed
    v4 🚀We no longer use this label since v4 is now the default model.
    on Oct 10, 2023
  4. sinedied commented on Mar 27, 2024

    @sinedied
    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.

    Eric Jizba (@ejizba) is there a workaround when using the v4 extraInputs for setting the dataType?

  5. ejizba commented on Mar 28, 2024

    @ejizba
    ContributorAuthor

    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. Daniel Castro (@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.

  6. sinedied commented on Mar 29, 2024

    @sinedied
    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.

  7. rohsyl commented on Jul 18, 2024

    @rohsyl

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions