// Copyright 2016 wkh237@github. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
import {
NativeModules,
DeviceEventEmitter,
Platform,
NativeAppEventEmitter,
} from 'react-native'
const RNFetchBlob:RNFetchBlobNative = NativeModules.RNFetchBlob
/**
* Open a file using UIDocumentInteractionController
* @param {string} path Path of the file to be open.
* @param {string} scheme URI scheme that needs to support, optional
* @return {Promise}
*/
function previewDocument(path:string, scheme:string) {
if(Platform.OS === 'ios')
return RNFetchBlob.previewDocument('file://' + path, scheme)
else
return Promise.reject('RNFetchBlob.openDocument only supports IOS.')
}
/**
* Preview a file using UIDocumentInteractionController
* @param {string} path Path of the file to be open.
* @param {string} scheme URI scheme that needs to support, optional
* @return {Promise}
*/
function openDocument(path:string, scheme:string) {
if(Platform.OS === 'ios')
return RNFetchBlob.openDocument('file://' + path, scheme)
else
return Promise.reject('RNFetchBlob.previewDocument only supports IOS.')
}
/**
* Set excludeFromBackupKey to a URL to prevent the resource to be backuped to
* iCloud.
* @param {string} url URL of the resource, only file URL is supported
* @return {Promise}
*/
function excludeFromBackupKey(path:string) {
return RNFetchBlob.excludeFromBackupKey('file://' + path);
}
export default {
openDocument,
previewDocument,
excludeFromBackupKey
}
[1] openDocument
// tmp파일로 저장하고, 화면에 보여줌 (공유 눌러서 이미지 저장 가능)
export const iosFileDownloadOpenDocument = (fileLink: string) =>
RNFetchBlob.config({
fileCache: true,
appendExt: 'png', // ImageView 컴포넌트에 첨부할 때 확장자가 있어야하므로, 'jpg', 'png' 등 확장자 추가
})
.fetch('GET', fileLink, {
//some headers ..
})
.then(resp => {
// console.log(resp);
if (Platform.OS === 'ios') {
RNFetchBlob.ios.openDocument(resp.data);
}
});
[2] previewDocument
// tmp파일로 저장하고, 화면에 보여줌 (공유 눌러서 이미지 저장 가능)
export const iosFileDownloadPreviewDocument = (fileLink: string) =>
RNFetchBlob.config({
fileCache: true,
appendExt: 'png', // ImageView 컴포넌트에 첨부할 때 확장자가 있어야하므로, 'jpg', 'png' 등 확장자 추가
})
.fetch('GET', fileLink, {
//some headers ..
})
.then(resp => {
// console.log(resp);
if (Platform.OS === 'ios') {
RNFetchBlob.ios.previewDocument(resp.data);
}
});