Giter Site home page Giter Site logo

Comments (3)

Shuo-Mr avatar Shuo-Mr commented on July 29, 2024 1

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.

Shuo-Mr avatar Shuo-Mr commented on July 29, 2024

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.

Leo2018Wu avatar Leo2018Wu commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.