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

[file-system] Fix return type of getContentUriAsync #7192

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@ This is the log of notable changes to the Expo client that are developer-facing.

### 🛠 Breaking changes

- `FileSystem.getContentUriAsync` now returns a string. ([#7192](https://github.com/expo/expo/pull/7192) by [@lukmccall](https://github.com/lukmccall))

### 🎉 New features

- Add `readerMode` and `dismissButtonStyle` (iOS) and `enableDefaultShare` (Android) flags for `WebBrowser` ([#7221](https://github.com/expo/expo/pull/7221) by [@LinusU](https://github.com/LinusU)) & [@mczernek](https://github.com/mczernek))
Expand Down
6 changes: 2 additions & 4 deletions docs/pages/versions/unversioned/sdk/filesystem.md
Expand Up @@ -386,7 +386,7 @@ Take a `file://` URI and convert it into content URI (`content://`) so that it c
FileSystem.getContentUriAsync(uri).then(cUri => {
console.log(cUri);
IntentLauncher.startActivityAsync('android.intent.action.VIEW', {
data: cUri.uri,
data: cUri,
flags: 1,
});
});
Expand All @@ -398,9 +398,7 @@ FileSystem.getContentUriAsync(uri).then(cUri => {

#### Returns

Returns a Promise that resolves to an object with the following fields:

- **uri (_string_)** -- A `content://` URI pointing to the file. This is the same as the `fileUri` input parameter but in different format.
Returns a Promise that resolves to a _string_ containing a `content://` URI pointing to the file. The URI is the same as the `fileUri` input parameter but in a different format.

### `FileSystem.getFreeDiskStorageAsync()`

Expand Down
Expand Up @@ -187,8 +187,8 @@ public void getInfoAsync(String uriStr, Map<String, Object> options, Promise pro
Bundle result = new Bundle();
try {
InputStream is = "content".equals(uri.getScheme()) ?
getContext().getContentResolver().openInputStream(uri) :
openAssetInputStream(uri);
getContext().getContentResolver().openInputStream(uri) :
openAssetInputStream(uri);
if (is == null) {
throw new FileNotFoundException();
}
Expand Down Expand Up @@ -319,7 +319,7 @@ public void deleteAsync(String uriStr, Map<String, Object> options, Promise prom
promise.resolve(null);
} else {
promise.reject("E_FILE_NOT_FOUND",
"File '" + uri + "' could not be deleted because it could not be found");
"File '" + uri + "' could not be deleted because it could not be found");
}
}
} else {
Expand Down Expand Up @@ -354,7 +354,7 @@ public void moveAsync(Map<String, Object> options, Promise promise) {
promise.resolve(null);
} else {
promise.reject("E_FILE_NOT_MOVED",
"File '" + fromUri + "' could not be moved to '" + toUri + "'");
"File '" + fromUri + "' could not be moved to '" + toUri + "'");
}
} else {
throw new IOException("Unsupported scheme for location '" + fromUri + "'.");
Expand Down Expand Up @@ -424,7 +424,7 @@ public void makeDirectoryAsync(String uriStr, Map<String, Object> options, Promi
promise.resolve(null);
} else {
promise.reject("E_DIRECTORY_NOT_CREATED",
"Directory '" + uri + "' could not be created or already exists.");
"Directory '" + uri + "' could not be created or already exists.");
}
} else {
throw new IOException("Unsupported scheme for location '" + uri + "'.");
Expand All @@ -451,7 +451,7 @@ public void readDirectoryAsync(String uriStr, Map<String, Object> options, Promi
promise.resolve(result);
} else {
promise.reject("E_DIRECTORY_NOT_READ",
"Directory '" + uri + "' could not be read.");
"Directory '" + uri + "' could not be read.");
}
} else {
throw new IOException("Unsupported scheme for location '" + uri + "'.");
Expand Down Expand Up @@ -573,9 +573,7 @@ public void getContentUriAsync(String uri, Promise promise) {
checkIfFileDirExists(fileUri);
if ("file".equals(fileUri.getScheme())) {
File file = uriToFile(fileUri);
Bundle result = new Bundle();
result.putString("uri", contentUriFromFile(file).toString());
promise.resolve(result);
promise.resolve(contentUriFromFile(file).toString());
} else {
promise.reject("E_DIRECTORY_NOT_READ", "No readable files with the uri: " + uri + ". Please use other uri.");
}
Expand Down Expand Up @@ -634,17 +632,17 @@ public void update(long bytesRead, long contentLength, boolean done) {
};

OkHttpClient client =
getOkHttpClient().newBuilder()
.addNetworkInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
})
.build();
getOkHttpClient().newBuilder()
.addNetworkInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
})
.build();

Request.Builder requestBuilder = new Request.Builder();
if (isResume) {
Expand Down Expand Up @@ -785,8 +783,8 @@ private static Bundle translateHeaders(Headers headers) {
// multiple values for the same header
if (responseHeaders.get(headerName) != null) {
responseHeaders.putString(
headerName,
responseHeaders.getString(headerName) + ", " + headers.value(i));
headerName,
responseHeaders.getString(headerName) + ", " + headers.value(i));
} else {
responseHeaders.putString(headerName, headers.value(i));
}
Expand Down Expand Up @@ -861,10 +859,10 @@ interface ProgressListener {
private synchronized OkHttpClient getOkHttpClient() {
if (mClient == null) {
OkHttpClient.Builder builder =
new OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS);
new OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS);

CookieHandler cookieHandler = mModuleRegistry.getModule(CookieHandler.class);
if (cookieHandler != null) {
Expand Down Expand Up @@ -920,7 +918,7 @@ private void forceDelete(File file) throws IOException {
throw new IOException("Unable to delete directory " + file + ".");
}
} else if (!file.delete()) {
throw new IOException( "Unable to delete file: " + file);
throw new IOException("Unable to delete file: " + file);
}
}
}
}