You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Attach resource from mobile
This commit is contained in:
@ -7,7 +7,6 @@ function shimInit() {
|
||||
|
||||
shim.fetchBlob = async function(url, options) {
|
||||
if (!options || !options.path) throw new Error('fetchBlob: target file path is missing');
|
||||
if (!options.method) options.method = 'GET';
|
||||
|
||||
let headers = options.headers ? options.headers : {};
|
||||
let method = options.method ? options.method : 'GET';
|
||||
@ -39,6 +38,29 @@ function shimInit() {
|
||||
}
|
||||
}
|
||||
|
||||
shim.uploadBlob = async function(url, options) {
|
||||
if (!options || !options.path) throw new Error('uploadBlob: source file path is missing');
|
||||
|
||||
const headers = options.headers ? options.headers : {};
|
||||
const method = options.method ? options.method : 'POST';
|
||||
|
||||
try {
|
||||
let response = await RNFetchBlob.fetch(method, url, headers, RNFetchBlob.wrap(options.path));
|
||||
|
||||
// Returns an object that's roughtly compatible with a standard Response object
|
||||
return {
|
||||
ok: response.respInfo.status < 400,
|
||||
data: response.data,
|
||||
text: response.text,
|
||||
json: response.json,
|
||||
status: response.respInfo.status,
|
||||
headers: response.respInfo.headers,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new Error('uploadBlob: ' + method + ' ' + url + ': ' + error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
shim.readLocalFileBase64 = async function(path) {
|
||||
return RNFetchBlob.fs.readFile(path, 'base64')
|
||||
}
|
||||
|
Reference in New Issue
Block a user