栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Retrofit2将文件上传到AWS S3预签名URL

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Retrofit2将文件上传到AWS S3预签名URL

在同事的帮助下,这就是解决方案。

public interface UpdateImageInterface {    @PUT    Call<Void> updateImage(@Url String url, @Body RequestBody image);}

调用代码:

    String CONTENT_IMAGE = "image/jpeg";    File file = new File(localPhotoPath);    // create new file on device    RequestBody requestFile = RequestBody.create(MediaType.parse(CONTENT_IMAGE), file);        Retrofit retrofit = new Retrofit.Builder()        .baseUrl("http://www.dummy.com/")        .build();    UpdateImageInterface imageInterface = retrofit.create(UpdateImageInterface.class);    // imageUrl is the String as received from AWS S3    Call<Void> call = imageInterface.updateImage(imageUrl, requestFile);

Javadoc,获取有关

@Url
(类网址)和
baseUrl()
(类Retrofit.Builder)的信息

MediaType
是OkHttp库中的一个类,通常与Retrofit(均来自Square)一起使用。可以在Javadoc中找到有关传递给parse方法的常量的信息。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570175.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号