상수
The following constants are available on the
RNFS
export:MainBundlePath
(String
) The absolute path to the main bundle directory (not available on Android)
CachesDirectoryPath
(String
) The absolute path to the caches directory
ExternalCachesDirectoryPath
(String
) The absolute path to the external caches directory (android only)
DocumentDirectoryPath
(String
) The absolute path to the document directory
DownloadDirectoryPath
(String
) The absolute path to the download directory (on android only)
TemporaryDirectoryPath
(String
) The absolute path to the temporary directory (falls back to Caching-Directory on Android)
LibraryDirectoryPath
(String
) The absolute path to the NSLibraryDirectory (iOS only)
ExternalDirectoryPath
(String
) The absolute path to the external files, shared directory (android only)
ExternalStorageDirectoryPath
(String
) The absolute path to the external storage, shared directory (android only)
IMPORTANT: when using
ExternalStorageDirectoryPath
it's necessary to request permissions (on Android) to read and write on the external storage, here an example: React Native Offical Doc파일에 쓰기
import RNFS from 'react-native-fs'; //또는 var RNFS = require('react-native-fs'); const path = RNFS.DocumentDirectoryPath + '/request'; console.log("path : ", path); const request = { "title": lectureTitle, "classKind": category, "groupName": association, "certificateKind": certificate, "description": lectureContent, "price": fee, "period": 4, "studentCount": max, "region": area, "swimmingPoolId": 1, "equipmentList": [ { "name": "물안경", "price": 3000 }, { "name": "수영모", "price": 3000 } ] }; RNFS.writeFile(path, JSON.stringify(request), 'utf8') .then((success) => console.log("파일 쓰기 성공")) .catch((err) => console.log("파일쓰기 에러 ", err))
파일 다운로드
type DownloadFileOptions = { fromUrl: string; // URL to download file from toFile: string; // Local filesystem path to save the file to headers?: Headers; // An object of headers to be passed to the server background?: boolean; // Continue the download in the background after the app terminates (iOS only) discretionary?: boolean; // Allow the OS to control the timing and speed of the download to improve perceived performance (iOS only) cacheable?: boolean; // Whether the download can be stored in the shared NSURLCache (iOS only, defaults to true) progressInterval?: number; progressDivider?: number; begin?: (res: DownloadBeginCallbackResult) => void; progress?: (res: DownloadProgressCallbackResult) => void; resumable?: () => void; // only supported on iOS yet connectionTimeout?: number // only supported on Android yet readTimeout?: number // supported on Android and iOS backgroundTimeout?: number // Maximum time (in milliseconds) to download an entire resource (iOS only, useful for timing out background downloads) };
type DownloadResult = { jobId: number; // The download job ID, required if one wishes to cancel the download. See `stopDownload`. statusCode: number; // The HTTP status code bytesWritten: number; // The number of bytes written to the file };