MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / createFileInDownloads

Function createFileInDownloads

apps/toolbox/src/pages/fs-helper.ts:222–248  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

220
221let lastDownload: File;
222export function createFileInDownloads() {
223 if (!global.isAndroid) {
224 return;
225 }
226 const width = Screen.mainScreen.widthPixels;
227 const height = Screen.mainScreen.heightPixels;
228 const randomImageUrl = `https://picsum.photos/${width}/${height}.jpg?random=${Date.now()}`;
229
230 Http.getFile(randomImageUrl).then((result: File) => {
231 let file = File.android.createFile({
232 directory: AndroidDirectory.DOWNLOADS,
233 name: `${Date.now()}.jpg`,
234 mime: 'image/jpeg',
235 relativePath: `NativeScript`,
236 });
237 result
238 .copy(file.path)
239 .then((done) => {
240 lastDownload = file;
241 console.log('done: ' + done + '\n' + 'Original path: ' + result.path + '\n' + 'Copied to: ' + file.path + '\n' + 'Original size: ' + result.size + '\n' + 'Copy size: ' + file.size + '\n');
242 alert(`File saved in ${AndroidDirectory.DOWNLOADS}/NativeScript`);
243 })
244 .catch((error) => {
245 console.error(error);
246 });
247 });
248}
249
250export function createFileInGallery() {
251 if (!global.isAndroid) {

Callers

nothing calls this directly

Calls 6

alertFunction · 0.90
createFileMethod · 0.80
errorMethod · 0.80
getFileMethod · 0.65
copyMethod · 0.65
logMethod · 0.45

Tested by

no test coverage detected