【问题标题】:How to send image and description to the server using retrofit 2.0如何使用改造 2.0 将图像和描述发送到服务器
【发布时间】:2017-02-26 15:37:08
【问题描述】:

我正在使用改造将图像及其描述发送到服务器,但我无法解析 FileUtils.getFile 方法中的 getFile 方法。

这是我的代码:

分级:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    compile 'com.github.boxme:squarecamera:1.1.0'
    compile 'com.intuit.sdp:sdp-android:1.0.3'
    compile 'com.android.support:design:24.2.1'
    compile 'org.apache.commons:commons-io:1.3.2'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'com.google.android.gms:play-services:7.8.0'
  compile('org.apache.httpcomponents:httpmime:4.2.4')
    compile 'com.pnikosis:materialish-progress:1.7'
}

活动:

@NonNull
    private MultipartBody.Part prepareFilePart(String partName, Uri fileUri) {
        // https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java
        // use the FileUtils to get the actual file by uri
        File file = FileUtils.getFile(this, fileUri);// here i am not able to resolve getFile method 

        // create RequestBody instance from file
        RequestBody requestFile =
                RequestBody.create(
                        MediaType.parse(context.getContentResolver().getType(fileUri)),
                        file
                );
        return MultipartBody.Part.createFormData(partName, file.getName(), requestFile);


    }

【问题讨论】:

  • 那个类是从哪里来的?你看过那个类的 API 文档吗?

标签: android retrofit2


【解决方案1】:

你可能导入了错误的类

org.apache.commons.io.FileUtils

getFile(File directory, String... names)

我不认为this 是一个文件对象

对比

com.ipaulpro.afilechooser.utils.FileUtils

getFile(Context context, String uri)

【讨论】:

  • 你好@cricket_007,你能告诉我我必须在gradle中添加哪个库
  • 阅读代码中已有的评论... github 链接?那是你必须导入的类。您改为导入 commons io
  • 换句话说,无论您从哪里复制该代码,请返回并再次阅读它
  • 求帮助
  • AFAIK,你什么都不添加到 gradle,你直接下载这个文件到你的项目中github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-17
  • 2017-04-12
  • 2018-09-21
  • 1970-01-01
  • 2018-10-05
  • 2017-06-30
  • 1970-01-01
相关资源
最近更新 更多