首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将多个blob文件作为FormData从角度发送到后端(python烧瓶)?

如何将多个blob文件作为FormData从角度发送到后端(python烧瓶)?
EN

Stack Overflow用户
提问于 2022-06-14 05:25:24
回答 1查看 326关注 0票数 0

在我的例子中,我只从表单数据中得到了最后一张照片。我要所有的照片发送后端。

my.ts.component文件,

代码语言:javascript
复制
await Promise.all(blobUrls.map(async (blobUrl) => {
      const blob = await fetch(blobUrl).then(fetched => fetched.blob());
      this.formData = new FormData();
      this.formData.append('file', blob);
}));


const { url } = await this.service.uploadFile(this.clientId, this.formData, uuidv4())
  .toPromise().catch(err => {
    this.cliApiService.handleErrorMessage(err);
    throw err; 
  });

在service.ts中,

代码语言:javascript
复制
  uploadFile(client_id: string, formData, filename: string): Observable<any> {
    const options = this.generateFormOption(true);
    const queryUri = `${this.apiEndpoint}${this.apiPath}/storage/upload/${client_id}/${filename}`;
    return this.http.post<any[]>(queryUri, formData, options);
  }

在烧瓶里,

代码语言:javascript
复制
 storage_image_file_request.add_argument('file', location='files', required=True)

 class ImageUploadResource(BaseResource):
    @ns_storage.marshal_with(storage_image_url_message)
    def post(self, client_id: str, filename: str):
        args = storage_image_file_request.parse_args()
        files = args.get('file')

我想发送所有的formData,也想在烧瓶中获取所有的formData。现在,我只有一张照片,甚至我上传了两张照片。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-14 07:12:44

通过这样的声明可以解决我的问题。

代码语言:javascript
复制
export class myComponent implements OnInit {
 formData = new FormData();

 await Promise.all(blobUrls.map(async (blobUrl) => {
      const blob = await fetch(blobUrl).then(fetched => fetched.blob());
      this.formData.append('file', blob);
}));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72611888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档