我正在尝试Image从我的Android APP上传到Amazon AWS S3,我需要使用AWS Restful API.
我正在使用Retrofit 2来提出请求.
我的应用程序与Amazon S3成功连接并按预期执行请求,但是当我尝试Image从Bucket查看时,图片无法打开.我下载Image到我的电脑并尝试打开但仍然收到图像已损坏的消息.
让我们看看我的完整代码.
我的Gradle依赖项
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
compile 'net.danlew:android.joda:2.8.2'
Run Code Online (Sandbox Code Playgroud)
这里创建了一个文件并启动了请求
File file = new File(mCurrentPhotoPath);
RequestBody body = RequestBody.create(MediaType.parse("image/jpeg"), file);
uploadImage(body, "photo_name.jpeg");
Run Code Online (Sandbox Code Playgroud)
改造界面
public interface AwsS3 {
@Multipart
@PUT("/{Key}")
Call<String> upload(@Path("Key") String Key,
@Header("Content-Length") long length,
@Header("Accept") String accept,
@Header("Host") String host,
@Header("Date") String date,
@Header("Content-type") String contentType,
@Header("Authorization") String authorization,
@Part("Body") RequestBody …Run Code Online (Sandbox Code Playgroud)