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

update document-picker package to support the file protocol #31499

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ PODS:
- react-native-config/App (= 1.4.6)
- react-native-config/App (1.4.6):
- React-Core
- react-native-document-picker (8.1.1):
- react-native-document-picker (8.2.1):
- React-Core
- react-native-flipper (0.159.0):
- React-Core
Expand Down Expand Up @@ -1233,7 +1233,7 @@ SPEC CHECKSUMS:
react-native-blob-util: 99f4d79189252f597fe0d810c57a3733b1b1dea6
react-native-cameraroll: 8ffb0af7a5e5de225fd667610e2979fc1f0c2151
react-native-config: 7cd105e71d903104e8919261480858940a6b9c0e
react-native-document-picker: f68191637788994baed5f57d12994aa32cf8bf88
react-native-document-picker: 69ca2094d8780cfc1e7e613894d15290fdc54bba
react-native-flipper: dc5290261fbeeb2faec1bdc57ae6dd8d562e1de4
react-native-geolocation: 0f7fe8a4c2de477e278b0365cce27d089a8c5903
react-native-image-manipulator: c48f64221cfcd46e9eec53619c4c0374f3328a56
Expand Down
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -2876,9 +2876,10 @@ function setMoneyRequestParticipants(participants, isSplitRequest) {
/**
* @param {String} receiptPath
* @param {String} receiptFilename
* @param {String} type
*/
function setMoneyRequestReceipt(receiptPath, receiptFilename) {
Onyx.merge(ONYXKEYS.IOU, {receiptPath, receiptFilename, merchant: ''});
function setMoneyRequestReceipt(receiptPath, receiptFilename, type) {
Onyx.merge(ONYXKEYS.IOU, {receiptPath, receiptFilename, merchant: '', receiptFileType: type});
}

function setUpDistanceTransaction() {
Expand Down
5 changes: 3 additions & 2 deletions src/libs/fileDownload/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ function appendTimeToFileName(fileName) {
*
* @param {String} path - the blob url of the locally uplodaded file
* @param {String} fileName
* @param {String} type
* @param {Function} onSuccess
* @param {Function} onFailure
*
* @returns {Promise}
*/
const readFileAsync = (path, fileName, onSuccess, onFailure = () => {}) =>
const readFileAsync = (path, fileName, type = '', onSuccess, onFailure = () => {}) =>
new Promise((resolve) => {
if (!path) {
resolve();
Expand All @@ -181,7 +182,7 @@ const readFileAsync = (path, fileName, onSuccess, onFailure = () => {}) =>
return res.blob();
})
.then((blob) => {
const file = new File([blob], cleanFileName(fileName), {type: blob.type});
const file = new File([blob], cleanFileName(fileName), {type: blob.type || type});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this change for? blob doesn't return type in updated version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested and confirmed that type isn't returned in old version as well.
So what exactly does this change fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For only the files which does have Space in their name, as you told upload failing for files which does have space init, after some digging type is the issue for the files which does have the space.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! But I said it's out of scope as it already happens on main and has different root cause.
Let's just fix crash here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, ok then. Fine. Will update the code to just have the fix.

file.source = path;
// For some reason, the File object on iOS does not have a uri property
// so images aren't uploaded correctly to the backend
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/ReceiptSelector/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function ReceiptSelector({route, report, iou, transactionID, isInTabNavigator, s
return;
}
const filePath = file.uri;
IOU.setMoneyRequestReceipt(filePath, file.name);
IOU.setMoneyRequestReceipt(filePath, file.name, file.type);

if (transactionID) {
IOU.replaceReceipt(transactionID, file, filePath);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ function MoneyRequestConfirmPage(props) {
const onFailure = () => {
Navigation.goBack(ROUTES.MONEY_REQUEST.getRoute(iouType, reportID));
};
FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptFilename, onSuccess, onFailure);
}, [props.iou.receiptPath, props.iou.receiptFilename, isManualRequestDM, iouType, reportID]);
FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptFilename, props.iou.receiptFileType, onSuccess, onFailure);
}, [props.iou.receiptPath, props.iou.receiptFilename, isManualRequestDM, iouType, reportID, props.iou.receiptFileType]);

useEffect(() => {
// ID in Onyx could change by initiating a new request in a separate browser tab or completing a request
Expand Down
Loading