Help me download the archive, please.
I get this json from the backend.
{
"version": "1.1",
"content": {
"headers": [
{
"key": "Content-Length",
"value": [
"4838778"
]
},
{
"key": "Content-Disposition",
"value": [
"attachment; filename=Archive.zip"
]
},
{
"key": "Content-Type",
"value": [
"application/zip"
]
}
]
},
"statusCode": 200,
"reasonPhrase": "OK",
"headers": [],
"trailingHeaders": [],
"requestMessage": null,
"isSuccessStatusCode": true
}
I am trying to download it like this.
function download(){
axios.defaults.responseType = 'blob'
axios.post('https://localhost:7120/api/Import/UploadFile', {
SipName: 'login',
SipPasw: "password"
})
.then((r)=>{
console.log(r)
var fileURL=window.URL.createObjectURL(new Blob([r.data]));
var fileLink=document.createElement('a');
fileLink.href=fileURL;
fileLink.setAttribute('download', "Archive.zip");
document.body.appendChild(fileLink);
fileLink.click();
})
.catch((e)=>{
console.log(e)
})
}
But the broken archive is downloaded.
In JSON, it can be seen that 4 megabytes are accumulated there, and an archive weighing 332 bytes is downloaded.
As I understand it, I'm not downloading the archive that I sent, but downloading the incoming JSON in zip format. But how to download the archive from the answer?
Related
My team is building a health app and thus using Asymmetrik FHIR API Server. We need to save a bundle consisting of Condition, Observation and Procedure. The bundle should create each individual object in their respective tables. But when we are using postman to hit the base URL with a very simple bundle object it is giving Invalid URL. Each service is individually working fine and able to create respective objects. How can we enable the root URL of this FHIR server?
POST URL: http://localhost:3000/4_0_0/
POST Object:
{
"resourceType": "Bundle",
"id": "f001",
"type": "transaction",
"entry": [
{
"resource": {
"resourceType": "Observation",
"status": "registered"
},
"request": {
"method": "POST",
"url": "Observation"
}
},
{
"resource": {
"resourceType": "Condition",
"code": {
"coding": {
"system": "http://hl7.org/fhir/ValueSet/condition-code",
"code": "",
"display": ""
}
}
},
"request": {
"method": "POST",
"url": "Condition"
}
}
]
}
ERROR:
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "not-found",
"details": {
"text": "Invalid url: /4_0_0/"
}
}
]
}
To prevent users from posting links to phishing scams on our Discord server, I have decided to use the Google Safe Browsing API.
Google Transparency Report (which to my knowledge uses the Safe Browsing API) says that the site:
contains harmful content, including pages that:
Try to trick visitors into sharing personal info or downloading software
See transparencyreport.google.com
However, when using the safe browsing API through node-js, using the googleapis package, I get a following response for this website (stringified GaxiosPromise<Schema$GoogleSecuritySafebrowsingV4FindThreatMatchesResponse>):
{
"config": {
"url": "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=...",
"method": "POST",
"userAgentDirectives": [
{
"product": "google-api-nodejs-client",
"version": "5.0.3",
"comment": "gzip"
}
],
"data": {
"client": {
"clientId": "tccpp-safety",
"clientVersion": "0.1.0"
},
"threatInfo": {
"threatTypes": [
"MALWARE",
"SOCIAL_ENGINEERING",
"UNWANTED_SOFTWARE",
"POTENTIALLY_HARMFUL_APPLICATION",
"THREAT_TYPE_UNSPECIFIED"
],
"platformTypes": [
"ANY_PLATFORM",
"PLATFORM_TYPE_UNSPECIFIED"
],
"threatEntryTypes": [
"URL"
],
"threatEntries": [
{
"url": "https://steamcommunytiu.com/new/?partner=65855640&token=Kj48sll3"
}
]
}
},
"headers": {
"x-goog-api-client": "gdcl/5.0.3 gl-node/12.21.0 auth/7.3.0",
"Accept-Encoding": "gzip",
"User-Agent": "google-api-nodejs-client/5.0.3 (gzip)",
"Content-Type": "application/json",
"Accept": "application/json"
},
"params": {
"key": "..."
},
"retry": true,
"body": "{\"client\":{\"clientId\":\"tccpp-safety\",\"clientVersion\":\"0.1.0\"},\"threatInfo\":{\"threatTypes\":[\"MALWARE\",\"SOCIAL_ENGINEERING\",\"UNWANTED_SOFTWARE\",\"POTENTIALLY_HARMFUL_APPLICATION\",\"THREAT_TYPE_UNSPECIFIED\"],\"platformTypes\":[\"ANY_PLATFORM\",\"PLATFORM_TYPE_UNSPECIFIED\"],\"threatEntryTypes\":[\"URL\"],\"threatEntries\":[{\"url\":\"https://steamcommunytiu.com/new/?partner=65855640&token=Kj48sll3\"}]}}",
"responseType": "json"
},
"data": {},
"headers": { ... },
"status": 200,
"statusText": "OK",
"request": {
"responseURL": "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=..."
}
}
This was printed using the following code snippet:
const response = await safebrowsing.threatMatches.find({ requestBody: body });
console.log(JSON.stringify(response, undefined, 4));
You can see that the data section in the response object is completely empty and normally this is where the matches array should be.
Am I using the API wrong? The Safe Browsing Lookup API says that ULRs do not need to be canonicalized or encoded.
I am trying to download the tar file in node-red.
Following is my JavaScript code to download the file.
downloadTar(sendObj).then(res => {
var bytes = new Uint8Array(byte); // pass your byte response to this constructor
var blob = new Blob([bytes], {type: "application/tar"});
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
var fileName = 'genome.tar';
link.download = fileName;
link.click();
});
function downloadTar(data) {
return new Promise((resolve, reject) => {
$.ajax({
url: nodeRedDownloadTar,
type: 'POST',
data: data,
success: function (result) {
resolve(result);
}
});
});
}
Following is my Node-Red flow, I am reading the file in a single Buffer Object and sending it to the http response
Then following is the response I am getting it from the backend.
The problem is the tar file is not getting downloaded. I am not sure where I am making the problem.
The following flow is working properly, I'm using the headers option in the http-response node to set the content-type to appplication/x-tar
[
{
"id": "6e993a09.f44244",
"type": "file in",
"z": "1c834717.22be01",
"name": "",
"filename": "/home/pi/test.tar",
"format": "",
"chunk": false,
"sendError": false,
"encoding": "none",
"x": 600,
"y": 580,
"wires": [
[
"6e7d5f6f.c9477"
]
]
},
{
"id": "df49df3b.d325b",
"type": "http in",
"z": "1c834717.22be01",
"name": "",
"url": "/tar",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 380,
"y": 580,
"wires": [
[
"6e993a09.f44244"
]
]
},
{
"id": "6e7d5f6f.c9477",
"type": "http response",
"z": "1c834717.22be01",
"name": "",
"statusCode": "",
"headers": {
"content-type": "application/x-tar"
},
"x": 800,
"y": 580,
"wires": []
}
]
I am able to read this JSON file but I am not able to read object URI JSON file. How can I use Object URI JSON File?
And this is the way I tried to read Uri JSON object
componentDidMount(){
const { match: { params } } = this.props;
axios.get(params.uri).then((res)=>{
const question = res.data[0]['uri'];
console.log(question);
this.setState({ question });
})
}
This is JSON file where Object URI contains a JSON file so how to read
[
{
"id": 59413,
"thumbnail": {
"id": "60255",
"title": "dornoch-castle-whisky-bar",
"alt": "dornoch-castle-whisky-bar",
"url": "https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg",
"courtesy": "",
"position": "center"
},
"thumbnail_url": "https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg",
"slug": "dornoch-castle-scotland-whisky",
"uri": "http://trivago-magazine-work-sample-server.s3-website.eu-central-1.amazonaws.com/dornoch-castle-scotland-whisky.json",
"title": "Dornoch Castle: A Whisky Tasting at One of the World's Most Popular Hotel Bars",
"card_title": "Whisky Tasting at Dornoch Castle in the Scottish Highlands",
"show_publish_date": false,
"date": "January 29th, 2019",
"newsletter_popup": false,
"newsletter_popup_header_image": false,
"taxonomies": {
"destinations": [
{
"name": "Europe",
"uri": "/destination/international/europe",
"slug": "europe",
"term_id": 1384
}
],
"themes": [],
"types": [
{
"name": "Nature",
"uri": "/type/nature",
"slug": "nature",
"term_id": 1380
}
]
},
"excerpt": "Dornoch Castle has amassed a whisky collection unlike most any other in the world. trivago Magazine Editor, Joe Baur, signs up for their whisky tasting. Video below."
},
Using the same way you extracted the first uri json data, fire another request to get the data from the second uri = res.data[0]['uri']
componentDidMount(){
const { match: { params } } = this.props;
axios.get(params.uri).then((res)=>{
const question = res.data[0]['uri'];
axios.get(question).then((qRes) => {
console.log(qRes); //will return the data from the second uri
})
console.log(question);
this.setState({ question });
})
}
I think this is just a normal JSON. You can get the file by reading direct to field url and thumnail_url
"url": "https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg",
You can show this file by
<img src="https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg" />
i am trying to send a batch request with graph api batch request using axios.
When I tried with postman i tried the following -
I am trying to post a send api with batch request.
url = https://graph.facebook.com?access_token=EA...`.
raw body = `{
"batch":[
{
"method": "POST",
"relative_url": "me/messages?access_token=<ACCESS_TOKEN>",
"body": "{ \"messaging_type\": \"MESSAGE_TAG\",\r\n \"tag\": \"ISSUE_RESOLUTION\",\r\n \"recipient\": {\r\n \"id\": \"1111944272264076\"\r\n },\r\n \"message\": {\r\n \"text\": \"hello, world!\"\r\n }}"
}
]
}
and the response is
[
{
"code": 400,
"headers": [
{
"name": "WWW-Authenticate",
"value": "OAuth \"Facebook Platform\" \"invalid_request\" \"(#100) The parameter recipient is required\""
},
{
"name": "Expires",
"value": "Sat, 01 Jan 2000 00:00:00 GMT"
},
{
"name": "Strict-Transport-Security",
"value": "max-age=15552000; preload"
},
{
"name": "Facebook-API-Version",
"value": "v2.10"
},
{
"name": "Content-Type",
"value": "text/javascript; charset=UTF-8"
},
{
"name": "X-App-Usage",
"value": "{\"call_count\":0,\"total_cputime\":0,\"total_time\":0}"
},
{
"name": "Access-Control-Allow-Origin",
"value": "*"
},
{
"name": "Cache-Control",
"value": "no-store"
},
{
"name": "Vary",
"value": "Accept-Encoding"
},
{
"name": "Pragma",
"value": "no-cache"
}
],
"body": "{\"error\":{\"message\":\"(#100) The parameter recipient is required\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"BdrR5exbYCu\"}}"
}
]
response code is 200. i have given recipient in body.
You don't need to URL encode the entire body. Only the content of each parameter. Try this as the body for request:
{
"batch":[
{
"method":"POST",
"relative_url":"me/messages",
"body": "recipient={\"id\": \"1111944272264076\"}&message={\"text\": \"hello, world!\"}"
}
]
}
Note: Instead of URL coding, I just escaped the characters. Makes the code much more readable