假设我有一个完整的文件路径,如:(/ sdcard/tlogo.png).我想知道它的mime类型.
我为它创建了一个函数
public static String getMimeType(File file, Context context)
{
Uri uri = Uri.fromFile(file);
ContentResolver cR = context.getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getExtensionFromMimeType(cR.getType(uri));
return type;
}
Run Code Online (Sandbox Code Playgroud)
但是当我调用它时,它返回null.
File file = new File(filePath);
String fileType=CommonFunctions.getMimeType(file, context);
Run Code Online (Sandbox Code Playgroud) 我曾提到过检查“上传和下载”进度, 使用Android版Drive API以及可直接和可恢复媒体上传的可恢复上传。
但是,我无法从中获得解决方案,可恢复媒体上传始终失败。
我的测试步骤是尝试在上传过程中断开WiFi连接/连接到另一个WiFi,然后再次上传相同的文件,但始终从头开始上传文件。
任何建议表示赞赏。
Logcat:
08-13 21:56:02.541 13190 13968 D UploadFileActivity: [MEDIA_IN_PROGRESS] progress: 19%
08-13 21:56:02.931 13190 13968 D UploadFileActivity: [MEDIA_IN_PROGRESS] progress: 19%
08-13 21:56:03.262 13190 13968 W System.err: javax.net.ssl.SSLException: Read error: ssl=0x7ac0ba00: I/O error during system call, Connection timed out
08-13 21:56:03.262 13190 13968 W System.err: at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
08-13 21:56:03.262 13190 13968 W System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:692)
08-13 21:56:03.262 13190 13968 W System.err: at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:168)
08-13 21:56:03.262 13190 13968 W System.err: at …Run Code Online (Sandbox Code Playgroud) 我需要帮助编写大文件(> 5MB)的分段和可恢复上传,到目前为止,我只能启动分段上传,但我不知道当用户暂停或网络故障时如何恢复它。
我所说的“恢复”是指我不知道如何
1) 获取已上传到驱动器的总字节数
2) 如何在 Content-Range 标头中使用该值
3)如何通过用户交互来暂停此上传[executeAsInputStream()也许?]
这就是我到目前为止所做的。即使我要强行停止应用程序并重新启动它,我也需要代码从停止上传的位置恢复
Drive service = GDrive.getService(); //Drive Specific Initialization Copied From QuickStart But with DriveScopes.FILES
File fileMetadata = new File();
fileMetadata.setName("Video.mp4"); //Video File
fileMetadata.setMimeType("application/vnd.google-apps.video");
java.io.File filePath = new java.io.File("E:\\large-file-60MB.mp4");//Large File Of 60 Mega Bytes
FileContent mediaContent = new FileContent("video/mp4",filePath);
Drive.Files.Create create=service.files().create(fileMetadata,mediaContent);
MediaHttpUploader uploader=create.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false); //Use Resumable MultiPart Upload Protocol
uploader.setChunkSize(2*MediaHttpUploader.MINIMUM_CHUNK_SIZE); //Chunks Of Bytes To Upload With Each Request
// HttpHeaders headers=new HttpHeaders();
// headers.put("Content-Range",?); //This is not actual code …Run Code Online (Sandbox Code Playgroud)