Download image from url on iOS React Native FS
up vote
0
down vote
favorite
I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:
/Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.
On real device, it's path (iPhone 8 Plus):
/var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg
I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;
because when i pick image from photo on real device this is path:
file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg
but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?
This is my code:
downloadImage = () => {
// download(this.props.image.url, '_Subiz/image_' + this.props.image.name);
this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)
};
download = async (target, destination) => {
try{
let options = {
fromUrl: target,
toFile: destination,
begin: (res) => {
console.log(res)
},
progress: (data) => {
console.log(data)
},
background: true,
progressDivider: 1
};
console.log(options);
const request = await RNFS.downloadFile(options).promise
console.log(request)
}catch(e){
console.log(e)
}
};
ios react-native
add a comment |
up vote
0
down vote
favorite
I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:
/Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.
On real device, it's path (iPhone 8 Plus):
/var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg
I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;
because when i pick image from photo on real device this is path:
file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg
but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?
This is my code:
downloadImage = () => {
// download(this.props.image.url, '_Subiz/image_' + this.props.image.name);
this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)
};
download = async (target, destination) => {
try{
let options = {
fromUrl: target,
toFile: destination,
begin: (res) => {
console.log(res)
},
progress: (data) => {
console.log(data)
},
background: true,
progressDivider: 1
};
console.log(options);
const request = await RNFS.downloadFile(options).promise
console.log(request)
}catch(e){
console.log(e)
}
};
ios react-native
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:
/Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.
On real device, it's path (iPhone 8 Plus):
/var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg
I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;
because when i pick image from photo on real device this is path:
file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg
but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?
This is my code:
downloadImage = () => {
// download(this.props.image.url, '_Subiz/image_' + this.props.image.name);
this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)
};
download = async (target, destination) => {
try{
let options = {
fromUrl: target,
toFile: destination,
begin: (res) => {
console.log(res)
},
progress: (data) => {
console.log(data)
},
background: true,
progressDivider: 1
};
console.log(options);
const request = await RNFS.downloadFile(options).promise
console.log(request)
}catch(e){
console.log(e)
}
};
ios react-native
I use react-native-fs to download image from url in iOS. I check on simulator it's download success with path:
/Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.
On real device, it's path (iPhone 8 Plus):
/var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg
I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;
because when i pick image from photo on real device this is path:
file:///var/mobile/Containers/Data/Application/8DE01885-DEFE-4667-B6FF-CE693A0DADB3/Documents/images/1520FCA5-80AB-4300-A7F6-2D2C974D726A.jpg
but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?
This is my code:
downloadImage = () => {
// download(this.props.image.url, '_Subiz/image_' + this.props.image.name);
this.download(this.props.image.url, `${RNFS.DocumentDirectoryPath}/react-native.png`)
};
download = async (target, destination) => {
try{
let options = {
fromUrl: target,
toFile: destination,
begin: (res) => {
console.log(res)
},
progress: (data) => {
console.log(data)
},
background: true,
progressDivider: 1
};
console.log(options);
const request = await RNFS.downloadFile(options).promise
console.log(request)
}catch(e){
console.log(e)
}
};
ios react-native
ios react-native
edited Nov 12 at 11:37
Milad Bahmanabadi
585617
585617
asked Nov 12 at 8:16
Hoàng Vũ Anh
13812
13812
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library
const { fs } = RNFetchBlob;
let Picture = fs.dirs.PictureDir;
RNFetchBlob
.config({
appendExt : 'png',
fileCache: true,
path: Picture+(new Date()).getTime()+'.png',
})
.fetch('GET', 'image_url')
.then((resp) => {
// the image path you can use it directly with Image component
console.log(resp.path());
return resp.readFile('base64'); // If you get base64 file
})
.then((base64Data) => {
console.log(base64Data);
}).catch((errorMessage, statusCode) => {
// error handling
console.log('errorMessage2:'+errorMessage)
});
I try and it's not work. I can't see image in library on my iPhone. This is path after download done:=================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
– Hoàng Vũ Anh
Nov 13 at 3:45
check my updating answers
– Yasin Ugurlu
Nov 14 at 10:13
Thank for answer but Picture isundefined
and it's not working
– Hoàng Vũ Anh
Nov 15 at 9:03
Are u sure define let Picture = fs.dirs.PictureDir;
– Yasin Ugurlu
Nov 15 at 13:07
Yes, of course, and it'sundefined
– Hoàng Vũ Anh
Nov 16 at 2:15
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258137%2fdownload-image-from-url-on-ios-react-native-fs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library
const { fs } = RNFetchBlob;
let Picture = fs.dirs.PictureDir;
RNFetchBlob
.config({
appendExt : 'png',
fileCache: true,
path: Picture+(new Date()).getTime()+'.png',
})
.fetch('GET', 'image_url')
.then((resp) => {
// the image path you can use it directly with Image component
console.log(resp.path());
return resp.readFile('base64'); // If you get base64 file
})
.then((base64Data) => {
console.log(base64Data);
}).catch((errorMessage, statusCode) => {
// error handling
console.log('errorMessage2:'+errorMessage)
});
I try and it's not work. I can't see image in library on my iPhone. This is path after download done:=================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
– Hoàng Vũ Anh
Nov 13 at 3:45
check my updating answers
– Yasin Ugurlu
Nov 14 at 10:13
Thank for answer but Picture isundefined
and it's not working
– Hoàng Vũ Anh
Nov 15 at 9:03
Are u sure define let Picture = fs.dirs.PictureDir;
– Yasin Ugurlu
Nov 15 at 13:07
Yes, of course, and it'sundefined
– Hoàng Vũ Anh
Nov 16 at 2:15
|
show 7 more comments
up vote
0
down vote
If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library
const { fs } = RNFetchBlob;
let Picture = fs.dirs.PictureDir;
RNFetchBlob
.config({
appendExt : 'png',
fileCache: true,
path: Picture+(new Date()).getTime()+'.png',
})
.fetch('GET', 'image_url')
.then((resp) => {
// the image path you can use it directly with Image component
console.log(resp.path());
return resp.readFile('base64'); // If you get base64 file
})
.then((base64Data) => {
console.log(base64Data);
}).catch((errorMessage, statusCode) => {
// error handling
console.log('errorMessage2:'+errorMessage)
});
I try and it's not work. I can't see image in library on my iPhone. This is path after download done:=================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
– Hoàng Vũ Anh
Nov 13 at 3:45
check my updating answers
– Yasin Ugurlu
Nov 14 at 10:13
Thank for answer but Picture isundefined
and it's not working
– Hoàng Vũ Anh
Nov 15 at 9:03
Are u sure define let Picture = fs.dirs.PictureDir;
– Yasin Ugurlu
Nov 15 at 13:07
Yes, of course, and it'sundefined
– Hoàng Vũ Anh
Nov 16 at 2:15
|
show 7 more comments
up vote
0
down vote
up vote
0
down vote
If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library
const { fs } = RNFetchBlob;
let Picture = fs.dirs.PictureDir;
RNFetchBlob
.config({
appendExt : 'png',
fileCache: true,
path: Picture+(new Date()).getTime()+'.png',
})
.fetch('GET', 'image_url')
.then((resp) => {
// the image path you can use it directly with Image component
console.log(resp.path());
return resp.readFile('base64'); // If you get base64 file
})
.then((base64Data) => {
console.log(base64Data);
}).catch((errorMessage, statusCode) => {
// error handling
console.log('errorMessage2:'+errorMessage)
});
If you use https://github.com/joltup/rn-fetch-blob library. You can download simple way yor image. And also you can see it in Photo library
const { fs } = RNFetchBlob;
let Picture = fs.dirs.PictureDir;
RNFetchBlob
.config({
appendExt : 'png',
fileCache: true,
path: Picture+(new Date()).getTime()+'.png',
})
.fetch('GET', 'image_url')
.then((resp) => {
// the image path you can use it directly with Image component
console.log(resp.path());
return resp.readFile('base64'); // If you get base64 file
})
.then((base64Data) => {
console.log(base64Data);
}).catch((errorMessage, statusCode) => {
// error handling
console.log('errorMessage2:'+errorMessage)
});
edited Nov 14 at 10:12
answered Nov 12 at 13:59
Yasin Ugurlu
15217
15217
I try and it's not work. I can't see image in library on my iPhone. This is path after download done:=================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
– Hoàng Vũ Anh
Nov 13 at 3:45
check my updating answers
– Yasin Ugurlu
Nov 14 at 10:13
Thank for answer but Picture isundefined
and it's not working
– Hoàng Vũ Anh
Nov 15 at 9:03
Are u sure define let Picture = fs.dirs.PictureDir;
– Yasin Ugurlu
Nov 15 at 13:07
Yes, of course, and it'sundefined
– Hoàng Vũ Anh
Nov 16 at 2:15
|
show 7 more comments
I try and it's not work. I can't see image in library on my iPhone. This is path after download done:=================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
– Hoàng Vũ Anh
Nov 13 at 3:45
check my updating answers
– Yasin Ugurlu
Nov 14 at 10:13
Thank for answer but Picture isundefined
and it's not working
– Hoàng Vũ Anh
Nov 15 at 9:03
Are u sure define let Picture = fs.dirs.PictureDir;
– Yasin Ugurlu
Nov 15 at 13:07
Yes, of course, and it'sundefined
– Hoàng Vũ Anh
Nov 16 at 2:15
I try and it's not work. I can't see image in library on my iPhone. This is path after download done:
=================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
– Hoàng Vũ Anh
Nov 13 at 3:45
I try and it's not work. I can't see image in library on my iPhone. This is path after download done:
=================================> ', '/var/mobile/Containers/Data/Application/9481E826-47FF-4BF0-B0E3-784161F01F00/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_9mqxc3swc17k85gnnva53'
– Hoàng Vũ Anh
Nov 13 at 3:45
check my updating answers
– Yasin Ugurlu
Nov 14 at 10:13
check my updating answers
– Yasin Ugurlu
Nov 14 at 10:13
Thank for answer but Picture is
undefined
and it's not working– Hoàng Vũ Anh
Nov 15 at 9:03
Thank for answer but Picture is
undefined
and it's not working– Hoàng Vũ Anh
Nov 15 at 9:03
Are u sure define let Picture = fs.dirs.PictureDir;
– Yasin Ugurlu
Nov 15 at 13:07
Are u sure define let Picture = fs.dirs.PictureDir;
– Yasin Ugurlu
Nov 15 at 13:07
Yes, of course, and it's
undefined
– Hoàng Vũ Anh
Nov 16 at 2:15
Yes, of course, and it's
undefined
– Hoàng Vũ Anh
Nov 16 at 2:15
|
show 7 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258137%2fdownload-image-from-url-on-ios-react-native-fs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown