【问题标题】:How to select any file from recent and upload it on server?如何从最近的文件中选择任何文件并将其上传到服务器上?
【发布时间】:2015-12-27 18:26:29
【问题描述】:

我想从安卓应用上传文件到服务器。因此用户可以从最近的图像、文档或 Android 应用程序中的任何 PDF 中选择任何文件,并将上传到服务器上。

所以请告诉我如何打开最近的活动并选择任何文件以及如何将其上传到服务器上。

请帮帮我,这对我来说非常重要。

【问题讨论】:

标签: android file-upload server image-upload recent-file-list


【解决方案1】:

您可以使用*/* 像在android 中一样打开所有文件。

Intent intent = new Intent();    
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, getString(R.string.perform_action_with)), attachmentChoice);

注意:attachmentChoice常量

【讨论】:

  • 你能告诉我如何上传文件(图片,PDF,DOC文件在服务器上)。我应该使用多部分还是其他东西,我如何知道用户选择了哪个文件?
  • 亲爱的,选择任何文件后,在您的 onActivityResult() 中,您可以从 URI 创建路径。然后你可以从那里获取文件类型。 public static String getFileType(String path) { String substring = path.substring(path.lastIndexOf("/") + 1); return substring.substring(substring.lastIndexOf(".") + 1); }
  • 从应用程序上传服务器文件的最佳方式是什么?
  • 我认为使用多部分服务。
  • 我可以使用多部分上传doc、pdf或其他文本文件吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-25
  • 2014-03-30
相关资源
最近更新 更多