superagent - attach blobs to request.

This commit is contained in:
Michael Ledin 2017-06-02 22:51:52 +03:00
parent df04a6e201
commit eab5bd9833
2 changed files with 3 additions and 1 deletions

View File

@ -94,7 +94,7 @@ declare namespace request {
interface Request extends Promise<Response> /* extends NodeJS.WritableStream */ {
abort(): void;
accept(type: string): this;
attach(field: string, file: string, filename?: string): this;
attach(field: string, file: string | Blob, filename?: string): this;
auth(user: string, name: string): this;
buffer(val?: boolean): this;
clearTimeout(): this;

View File

@ -262,11 +262,13 @@ stream.pipe(req);
})();
// Attaching files
const blob: Blob = new File([], 'thor.png');
request
.post('/upload')
.attach('avatar', 'path/to/tobi.png', 'user.png')
.attach('image', 'path/to/loki.png')
.attach('file', 'path/to/jane.png')
.attach('blob', blob)
.end(callback);
// Field values