empty request bodies with file upload to Node/Expr

2019-09-01 15:04发布

I'm using ng-flow to upload a picture.

I need to set my upload to content type application/json: Node (Express) request body empty but how?

I'm basing my code off the sample here:

https://github.com/flowjs/flow.js/tree/master/samples/Node.js

I'm guessing its in the header configuration, but I'm guessing. here is my $scope.image object:

    { 
    image:  { 
    support: true
    supportDirectory: true
    files: 
    [  { 
    flowObj:  { 
    $ref: $
     } 
    file:  { 
    webkitRelativePath: 
    lastModifiedDate:  {  } 
    name: super-phillip (1).gif
    type: image/gif
    size: 931802
     } 
    name: super-phillip (1).gif
    size: 931802
    relativePath: super-phillip (1).gif
    uniqueIdentifier: 931802-super-phillip1gif
    chunks: 
    [  ]
    paused: false
    error: true
    averageSpeed: 0
    currentSpeed: 0
    _lastProgressCallback: 1399049249446
    _prevUploadedSize: 931802
    _prevProgress: 0
     }  ]
    defaults:  { 
    chunkSize: 1048576
    forceChunkSize: false
    simultaneousUploads: 3
    singleFile: false
    fileParameterName: file
    progressCallbacksInterval: 500
    speedSmoothingFactor: 0.1
    query:  {  } 
    headers:  {  } 
    withCredentials: false
    preprocess: null
    method: multipart
    prioritizeFirstAndLastChunk: false
    target: /
    testChunks: true
    generateUniqueIdentifier: null
    maxChunkRetries: 0
    chunkRetryInterval: null
    permanentErrors: 
    [ 404, 415, 500, 501 ]
    onDropStopPropagation: false
     } 
    opts:  { 
    chunkSize: 1048576
    forceChunkSize: false
    simultaneousUploads: 1
    singleFile: true
    fileParameterName: file
    progressCallbacksInterval: 500
    speedSmoothingFactor: 0.1
    query:  { 
    $ref: $["defaults"]["query"]
     } 
    headers:  { 
    $ref: $["defaults"]["headers"]
     } 
    withCredentials: false
    preprocess: null
    method: multipart
    prioritizeFirstAndLastChunk: false
    target: ./upload
    testChunks: true
    generateUniqueIdentifier: null
    maxChunkRetries: 3
    chunkRetryInterval: 5000
    permanentErrors: 
    [ 404, 501 ]
    onDropStopPropagation: false
     } 
    events:  { 
    catchall: 
    [ null, null ]
     } 
    onDrop: null
    preventEvent: null
     } 
     } 

1条回答
劳资没心,怎么记你
2楼-- · 2019-09-01 15:46

the newest express bodyParser() doesn't allow multipart-formdata anymore so you have to use a middleware, like connect-multiparty or multer https://github.com/expressjs/multer

查看更多
登录 后发表回答