Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fileCopyUri should include the URI schema #527

Merged

Conversation

kidroca
Copy link
Contributor

@kidroca kidroca commented Jan 18, 2022

Summary

Make the fileCopyUri be a URI string and include the schema prefix (usually file:/)

A URI should begin with the schema prefix
In iOS fileCopyUri already works that way
Missing the schema prefix causes a problem when you try to use fileCopyUri with fetch to upload a file

Why .toURI().toString()

This was the only method I've found that returned the schema as part of the string
The same thing is used in RN image picker here

Difference between file:/ and file:///

Since on iOS fileCopyUri is returned with a file:/// prefix - you might be wondering if this is a problem.
According to wikipedia file:/ and file:/// are the same thing: https://en.wikipedia.org/wiki/File_URI_scheme#How_many_slashes.3F

Test Plan

I've manually tested the changes in the example app and in an external app

Before (no file:/ prefix for fileCopyUri)

RN_Document_Picker_Before

 LOG  [
  {
    "size": 3028,
    "fileCopyUri": "/data/user/0/com.example.reactnativedocumentpicker/cache/7246f3d1-815b-45fa-86ce-a420da059da4/sample.pdf",
    "name": "sample.pdf",
    "type": "application/pdf",
    "uri": "content://com.android.providers.downloads.documents/document/18"
  }
]

After

RN_Document_Picker_After

 LOG  [
  {
    "size": 3028,
    "fileCopyUri": "file:/data/user/0/com.example.reactnativedocumentpicker/cache/d87a83fe-e393-40f2-9f5f-f3ebe2641974/sample.pdf",
    "name": "sample.pdf",
    "type": "application/pdf",
    "uri": "content://com.android.providers.downloads.documents/document/18"
  }
]

Sample video (after) in our app:

2022-01-18_21-40-23.mp4
  • You can see that we used to test whether fileCopyUri starts with a scheme and added file: if it didn't
  • Now that's no longer necessary

Sample for the same in iOS

No iOS change, but just showing how it already works there:
RN_Document_Picker_iOS

What's required for testing (prerequisites)?

This can be manually tested in the example app

What are the steps to reproduce (after prerequisites)?

  1. Use the example app on Android
  2. Use the "Open Picker For Single File Selection" button
    (Or any button that passes a copyTo Document Picker Option)
  3. Select a file
  4. See the displayed fileCopyUri - it should contain the URI schema in the beginning e.g. file:/

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • n/a I added the documentation in README.md
  • n/a I updated the typed files (TS and Flow)

Make the `fileCopyUri` be an actual URI and include the schema
prefix (usually `file:/`)

It already works that way on iOS
@vonovak
Copy link
Collaborator

vonovak commented Jan 19, 2022

thank you for the PR and the comprehensive description! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fileCopyUri has file:// prefix on iOS but doesn't on Android
2 participants