azure-function-multipart icon indicating copy to clipboard operation
azure-function-multipart copied to clipboard

Update "@azure/functions": "^3.2.0" to "^4.0.0"

Open kazto opened this issue 1 year ago • 4 comments

error TS2345: Argument of type 'import("C:/work/node_modules/@azure/functions/types/http").HttpRequest' is not assignable to parameter of type 'import("C:/work/node_modules/@anzp/azure-function-multipart/node_modules/@azure/functions/types/http").HttpRequest'.
  Type 'HttpRequest' is missing the following properties from type 'HttpRequest': get, parseFormBody

29     const { fields, files } = await parseMultipartFormData(request);
                                                              ~~~~~~~

#373 is similar to this Issue, but I believe the cause is different.

kazto avatar Apr 24 '24 09:04 kazto

Bump this - facing the same issue

TamimiGitHub avatar Aug 02 '24 08:08 TamimiGitHub

Since the library is not updated and probably won't be, would there be any other simple implementation based on its dependencies?

Using busboy directly, what would it look like...?

LucasBonafe avatar Aug 06 '24 18:08 LucasBonafe

Hey @LucasBonafe - I was able to achieve this by using the parse-multipart. To do this, you will have to read the raw body of the request as a buffer stream and make sure you extract the boundaries of the form-data using multipart. The following is an example

import * as multipart from 'parse-multipart';

# in your function

const rawBody = await request.body.getReader().read();
const contentType = request.headers.get('content-type');
const boundary = multipart.getBoundary(contentType);

if(boundary) {
try {
    let files: Form[] = multipart.Parse(Buffer.from(rawBody.value), boundary);
    # Print out all the files in the form-data body
    console.log(files)
    # Print out the content of the files
      files.map(file => context.log(file.data.toString()));
} catch (error) {
  return {status: 400, body: error};
}

TamimiGitHub avatar Aug 07 '24 06:08 TamimiGitHub