跳到主要内容

cloudflare 通过API上传文件到R2,但是文件类型显示application/octet-stream

问题

如图,我使用的是Java的aws-java-sdk-s3上传到CF的R2, 但是显示的的文件类型是application/octet-stream

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.701</version>
</dependency>

解决办法

在上传时增加metadata

上传的代码

    public void uploadFile(String identifier, InputStream inputStream, ObjectMetadata metadata) {
PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucket, identifier, inputStream, metadata);
this.client.putObject(putObjectRequest);
}

增加的metadata


ObjectMetadata metadata = new ObjectMetadata();
metadata.setHeader("Content-Type", "application/json");