Append image file to form data - Cordova/Angular

前端 未结 3 1286
遥遥无期
遥遥无期 2020-12-12 19:37

I am using Anuglar, Ionic and Cordova in my current project, and I\'m trying to POST FormData containing an image file to my server. Right now I\'m using the cordova camera

3条回答
  •  被撕碎了的回忆
    2020-12-12 20:31

    Your post was extremly helpful to fix my problem. I'm using Ionic 4 and trying to upload an image using standard http and file client. The key code for reference is here:

    return this.file.readAsArrayBuffer(path, file).
      then(blob => {
        const imgBlob = new Blob([blob], { type: 'image/jpeg' } );
    
        formData.append('image[file]', imgBlob);
    
        return this.http.post(url, formData, headers).subscribe();
    });

    Hope it helps someone out there as it did for me.

提交回复
热议问题