如何获得纯二进制文件

问题描述 投票:0回答:1

我有一个使用antdUpload上传的文件

html渲染器:

    <Upload
        beforeUpload={((file: RcFile, fileList: RcFile[]): boolean => {this.requestUpload(file, (fileList.length || 0 )); return false;})}
    ></Upload>

代码部分:

requestUpload(file: RcFile, nbFile: number): void {
    const r = new FileReader();
    r.onload = (): void => {
        FileHelper.uploadFile({
            filename: file.name,
            filepath: `${this.props.datastoreId}/${this.props.itemId}/${this.props.fieldId}/${file.name}`,
            file: r.result,
            field_id: this.props.fieldId,
            item_id: this.props.itemId || '',
            d_id: this.props.datastoreId || '',
            p_id: this.props.projectId || '',
            display_order: nbFile
        }).subscribe()
    };
    r.readAsArrayBuffer (file);
}

所以我从那一刻起得到一个RcFile(只是扩展了file类型),我不知道该怎么做才能获取文件的原始二进制文件。我的API仅适用于原始二进制文件,而没有其他功能。所以我需要file: r.result,是纯二进制原始数据。

我发现了另一个stackoverflow问题,但是他们都说应该怎么做(使用base64或其他方法),但是如果您没有其他选择来更改它,那么他们怎么做。

我该如何实现?

javascript typescript upload filereader antd
1个回答
0
投票

根据链接的文件上传工具(ng-file-upload),您应该首先:“ 在'ng-file-upload'标记下对StackOverflow提问。”因此,将该标记添加到这篇文章中。

然后,如果我在文档上对二进制文件使用Ctrl + F,我会看到:

Upload.http({
  url: '/server/upload/url',
  headers : {
    'Content-Type': file.type
  },
  data: file
})

好像他们正在将文件对象作为数据传递,并且文件类型位于标头中。我还没有尝试过...

© www.soinside.com 2019 - 2024. All rights reserved.