简体   繁体   中英

upload file from angular app to an azure function and then persist to blob storage

I want to upload an image to an azure function and there persist it to azure blob storage but I cannot find any good articles about how to do this.

SOme posts say it is not possible to do this as node azure functions have problems with multipart.

I don't want my client app to know what storage mechanism is used so I don't want to use azure-storage-node client library because we will be locked into using.

I've tried this code:

const upload = multer({ storage: multer.memoryStorage() });

module.exports = function(context: Context, req: any) {
  upload.any()(req, {} as any, function(err: any) {
    context.log('here we are');
    if (err) {
      throw err;
    }

    context.log(req.body);
    context.log(req);
    console.log(req.file);
    context.log(req.files);
    context.done(undefined, context);
  });

But req.files is undefined and I had to set the content type to application/octet-stream or else I got req.pipe is not a function .

How can I get the req.files into azure storage from an azure function?

Here is a sample GIT project which uses the @azure/storage-blob SDK to add blobs into Azure. It sounds like you don't want to use an SDK, so you could look at the SDK source and take the code you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM