Update "@azure/functions": "^3.2.0" to "^4.0.0"
kazto opened this issue · 3 comments
kazto commented
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.
TamimiGitHub commented
Bump this - facing the same issue
LucasBonafe commented
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...?
TamimiGitHub commented
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};
}