I downloaded icon on a domain of kintone with kintone.proxy. The response is in text format. I want to receive a blob object. Which way can i do to receive desire result?
Thanks
I downloaded icon on a domain of kintone with kintone.proxy. The response is in text format. I want to receive a blob object. Which way can i do to receive desire result?
Thanks
Hello Tan,
As Chris mentioned in the other post, https://developer.kintone.io/hc/en-us/community/posts/4549066182041
could you try and see by writing,
const data = { format: "RAW", value: new Blob([arrayBuffer]) };
resolves the issue you are having?
Hopefully, this helps.
Sean
Thanks, Sean,
Maybe my description is not clear. My problem: I am standing at domain A of Kintone, downloading an icon file (png) from domain B of Kintone using kintone.proxy
. Then, I upload the file's content to the current domain (domain A), and then I attempt to set the file key to general settings. Kintone informs me that the file is not in PNG, JPEG, etc. format. What can I do to resolve this problem?
get_file_dev(filekey, api_url='k/v1/file.json') {
let url = this.dev_domain + api_url + `?fileKey=${filekey}`;
return kintone.proxy(url, 'GET', header_dev, {}).then(resp => {
return resp[0];
}, error => {
throw `${error.message} get file key ${filekey} fail`;
});
}
upload_file_product(data, object_data, api_url='k/v1/file.json') {
return new Promise(function (resolve, reject) {
let blob = new Blob([data], {type: object_data['contentType']});
let formData = new FormData();
formData.append('__REQUEST_TOKEN__', kintone.getRequestToken());
formData.append('file', blob, object_data['name']);
let url = kintone.api.url(`/${api_url}`);
let xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onload = function() {
if (xhr.status === 200) {
// success
resolve(JSON.parse(xhr.responseText)['fileKey']);
} else {
reject(JSON.parse(xhr.responseText));
throw `${JSON.parse(xhr.responseText)} upload file ${object_data['name']} fail`;
}
};
xhr.send(formData);
});
}
Thank you for your support.
Hi Tan,
Thank you for your reply.
In the kintone.proxy function, only strings are supported as the response body returned by the proxy destination.
In other words, binary data such as images cannot be retrieved.
However, if you use the kintone.proxy.upload function, which uploads files to an external location, can execute file upload API.
https://kintone.dev/en/docs/kintone/js-api/other/kintone-proxy-upload/
https://kintone.dev/en/docs/kintone/rest-api/files/upload-file/
After downloading the file using XMLHttpRequest on domain B, execute the file upload API on domain B using the kintone.proxy.upload function on domain A.
Hopefully, this helps.
Hi Sean
Thank you for your support,
I must stand at domain A to download icon at domain B. So I can’t use XMLHttpRequest to download icon at domain B.
Thank you so much. You are kind