Comments (3)
I tried to look at the logic of the source code and found the wrong location,but I didn't go into the reasons.
The method is as follows:
` public void asyncUpload(final ReactContext context, String bucketName, String ossFile, String sourceFile, ReadableMap options, final Promise promise) {
// Content to file:// start
Uri selectedVideoUri = Uri.parse(sourceFile);
// 1. content uri -> file path
// 2. inputstream -> temp file path
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
// Here, the initialization fails, causing the getcolumnindexorthrow below to throw an exception
cursor = context.getCurrentActivity().getContentResolver().query(selectedVideoUri, proj, null, null, null);
if (cursor == null)
sourceFile = selectedVideoUri.getPath();
}
// error: cursor is null。The real reason for the path change is not in this, but in the exception handling
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
sourceFile = cursor.getString(column_index);
} catch (Exception e) {
// After the processing of the following method, the path has changed
// sourceFile = FileUtils.getFilePathFromURI(context.getCurrentActivity(), selectedVideoUri);
} finally {
if (cursor != null) {
cursor.close();
}
}
// init upload request
PutObjectRequest put = new PutObjectRequest(bucketName, ossFile, sourceFile);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("application/octet-stream");
put.setMetadata(metadata);
//
.....
//
// set callback
Log.d("AliyunOSS", "OSS uploadObjectAsync ok!");
}
`
After the annotation, the path is normal and the upload is successful. I think the method is to copy the file and then return a new file. I don't know whether it is for compression. But what happened was that the file couldn't be found.
// sourceFile = FileUtils.getFilePathFromURI(context.getCurrentActivity(), selectedVideoUri);
from aliyun-oss-react-native.
I also have this problem, saying that there is no such file, but the path of the error prompt is not my path at all
from aliyun-oss-react-native.
I tried to look at the logic of the source code and found the wrong location,but I didn't go into the reasons.
The method is as follows:
` public void asyncUpload(final ReactContext context, String bucketName, String ossFile, String sourceFile, ReadableMap options, final Promise promise) {
// Content to file:// start
Uri selectedVideoUri = Uri.parse(sourceFile);
// 1. content uri -> file path
// 2. inputstream -> temp file path
Cursor cursor = null;try { String[] proj = {MediaStore.Images.Media.DATA}; // Here, the initialization fails, causing the getcolumnindexorthrow below to throw an exception cursor = context.getCurrentActivity().getContentResolver().query(selectedVideoUri, proj, null, null, null); if (cursor == null) sourceFile = selectedVideoUri.getPath(); } // error: cursor is null。The real reason for the path change is not in this, but in the exception handling int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); sourceFile = cursor.getString(column_index); } catch (Exception e) { // After the processing of the following method, the path has changed // sourceFile = FileUtils.getFilePathFromURI(context.getCurrentActivity(), selectedVideoUri); } finally { if (cursor != null) { cursor.close(); } } // init upload request PutObjectRequest put = new PutObjectRequest(bucketName, ossFile, sourceFile); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType("application/octet-stream"); put.setMetadata(metadata); // .....
//
// set callback
Log.d("AliyunOSS", "OSS uploadObjectAsync ok!");
}
`
After the annotation, the path is normal and the upload is successful. I think the method is to copy the file and then return a new file. I don't know whether it is for compression. But what happened was that the file couldn't be found.
// sourceFile = FileUtils.getFilePathFromURI(context.getCurrentActivity(), selectedVideoUri);
I have try this way and it's work!
from aliyun-oss-react-native.
Related Issues (20)
- 请问还会更新吗? HOT 3
- 在pod install的时候 Installing AliyunOSSiOS 一直卡在这边 HOT 2
- com.aliyun.oss.clientError Code=6 HOT 1
- AliyunOSS.asyncDownload 下载文件问题
- android studio下,加载aliyun-oss-react-native包报错
- 请问下这个问题如何解决?Unable to resolve host "xxx.aliyuncs.com": No address associated with hostname
- 调用initWithSecurityToken会卡住js线程吗?
- 安装OSS模块后app launch compile错误 HOT 6
- android Q没有适配,上传图片路径会出错 HOT 1
- Attempt to invoke virtual method 'void com.reactlibrary.AliyunUploadManager.asyncUpload(com.facebook.react.bridge.ReactContext, java.lang.String, java.lang.String, java.lang.String, com.facebook.react.bridge.ReadableMap, com.facebook.react.bridge.Promise)' on a null object reference HOT 2
- 模块3年没有更新,已经abandoned? HOT 1
- AliyunUploadManager.java uses unchecked or unsafe operations.
- 公告:这个SDK后面有时间准备重新搞起来了,大家有issue,有PR的欢迎可以提交 HOT 17
- 上传图像在Android emulator运行通畅但在安桌手机上stuck HOT 1
- 请为 Expo 创建一个 Config Plugin
- yarn ios 报错 HOT 5
- 这个项目还在维护嘛?还能使用嘛? HOT 1
- Could not GET 'https://oss.sonatype.org/content/repositories/snapshots/com/aliyun/dpa/oss-android-sdk/2.3.0-SNAPSHOT/maven-metadata.xml'. Received status code 502 from server: Bad Gateway HOT 2
- 在Android10以上,上传文件失败,原因已找到,请修复
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aliyun-oss-react-native.