Error uploading PGP key to Google - pgp

I am uploading the BASE64 encoded key to Google using the instruction here but when I make the post request, I get the following response
Content-Type application/xml is not a valid input type
I'm posting this:
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:apps='bVFFTkJGQlVwVklCQ0FDL0NKK0VJR0RaeTJGdUJURU5qVnh2dko5Z29YL2lXTjlaZnByQVBDM1hm
TUZvZHdabQ0KdktNWVQxTVNBaFp0NWNqaXV4MUdvY2hNWnNwMVJZd0JxR2hQeUVNYnZ1MFA5R1RZ
ZnNpZjBjckRWNTNodU1FZg0KaGhRL2diRXZoU2loMWhvUGJES2JkSmFqZ2Z0R1g3cm83YUc2Ui9H
b1hTd3JQb1U4aEZYSmZubHZzNCs4ZFdnOA0Ka1hGZzFMSGFGM0MzbnQ4UWVGdU1QQ0d0TldWZGFj
cWlKTGtqbUNyV1FJOW1FZmpwcHJiZDUwcjNFeGxhb0JhbQ0KVEMzeEJvZ0xObG44UDFLb2xyZkVZ
OVV3bWxGanp5TWlqNU9kdEpvWFRRL1p0VWFHQUR5Q2pLaEY2ZXh2dFhVQw0KM092N2FZeWpCelM4
Ynd5dXgveEozSGNQYVE1MXpUT0UycDRIQUJFQkFBRzBKWFpwYzJobGMyZ2dQSFpwYzJobA0KYzJn
dWMybHVaMmhoYkRreFFHZHRZV2xzTG1OdmJUNkpBVGdFRXdFQ0FDSUZBbEJVcFZJQ0d3TUdDd2tJ
QndNQw0KQmhVSUFna0tDd1FXQWdNQkFoNEJBaGVBQUFvSkVGNXZjcnVkTjdSd0kzMEgvMUtnVDdk
WlVvTlM4bnFRa3lnVg0Ka3J1dS9oWEI1dWk3OXdNbjhMeUxvSDh1bjR4bFY1NnVjZ3dhWnI1WmZF
b0tQTzVHbDNJRHJrVmJuS3E5eWhVQg0KTVAwMmloMVlqZTNJcDRuUjU4L3lWdGhYMzhJb3VVMW9O
aVNOVjNqaEt5WGJEZXl5Rm1ldlRJM2NIYmNvbkt1Uw0KK3M1T0plYVp1OExQMTBCe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g2blVQRXpSVlBneHVUS09UQk9NZEhG
WGxDMXY4ZWcvNEVRSnhJamZQMg0KVnR5aW5EZmFZaTNESnQrN2h3anR5Y0VKdjFwOTdMemRDeWZq
S1dHVVliaHhYbFNFN0RZbW5VVWpoaTk0N3hvOQ0KdjV6bjZtZUVNd3phdzNGdUZyMHN3S1JPRVhy
aERuQnRyVG4wS1BxUGdBNGpPVFE5L1Q0Q2Q5Sk4wc3V2UFY3QQ0KODNBL1RNYWVURjdNTytBSGpH
YlArTEMwbi8rVzRTTHQvTVRFTW82QmlJM3R5eUJaUGIzc20zblhxT3B2bUFUbQ0KSEkxOWpYcENS
TlBrWmZWSENjRSswbGN4NDNMOFdtdnU5NUhHNkJ2ZjJJMmdBUll1cHpaZ3ZiV3BwMVRzZnRWZw0K
PUV2TWo="/>
</atom:entry>
What's wrong?
This is the same code given on google link , with base64 encoded key

I found the problem,which was causing error
I was not setting the header application/atom+xml
Also authorization must be done before doing the request,so one more header must be set with request Authorization: GoogleLogin auth={yourAuthToken}
HTH

Related

How to serve a file not saved in folder, stored in postgresql database, and to be rendered to HTML by expressjs?

We first sent the file to be posted as following:
router.post('/savefile', multer().single('filesource'), (q,s) => {
db.query("insert into filesource (filerefid, source) values ($1, $2) returning filerefid", [ q.body.filerefid, q.file ])
.then (r=> s.send(r.rows[0]))
})
And then tried to show that as following to the HTML:
<object type="application/pdf" data="http://localhost:3000/getsource/1"></object>
Which is requested by:
router.get('/getsource/:i', (q,s) => {
db.query('select source from filesource where filerefid = $1;',
[q.params.i])
.then (r=> s.send(Buffer.from(r.rows[0].source.buffer)))
})
However the files cant be showed or downloaded correctly like that, What is the best way of doing that, without saving file in any directory?
I suppose you are missing content type header in the response.
res.set('Content-Type', 'application/pdf');
Also consider setting Content-Disposition header to present a correct file name.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
Content-Type: application/pdf
Content-Disposition: attachment; filename="file.pdf"
Update
file property which is provided by multer is a js object, which contains buffer property with binary data of the file. In http get method this binary data should be returned decorated by the required http headers mentioned above.
As mentioned by Oleg Flores answer for correct header, and the notice in his comment, that we should use the buffer from the object, that in the case of not saving any file by Multer, values of the insert query should be
[ q.body.filerefid, q.file.buffer]

Uploading an image using Multipart by karate API tool [duplicate]

I have a simple POST request that requires a json Content-Type header and a body like
{
oneNbr: "2016004444",
twoCode: "###",
threeNbr: "STD PACK",
sheetTitle: "010000",
codeType: "AF14"
}
When I run this in Postman, it runs as expected, returning 200 status and the expected response.
Here's the same script in Karate:
Scenario: Sample test
* def payload =
"""
{
oneNbr: "2016004444",
twoCode: "###",
threeNbr: "STD PACK",
sheetTitle: "010000",
codeType: "AF14"
}
"""
Given path '/my_end_point/endpoint'
And request payload
When method post
Then status 200
When I run this, it returns {"code":"415","status":"Unsupported Media Type"}. The console output shows that the right content-type is being set during the POST.
Even if I specifically set the content-type in the script, 415 is still returned e.g.
And header Content-Type = 'application/json'
OR
* configure headers = { 'Content-Type': 'application/json' }
Any help is appreciated.
We did some debugging and found that Karate automatically appends 'charset=UTF-8' to the Content-Type header. The API does not expect charset.
Found the following post and that solved the problem:
How can I send just 'application/json' as the content-type header with Karate?
Posting this to help others in future.
It's simple. Try to use this in your background.
* def charset = null
Try adding a * header Accept = 'application/json' header. The one difference between Karate and Postman is that Postman tries to be smart and auto-adds an Accept header - whereas Karate does not.

How do I send raw binary data via HTTP in node.js?

From a node.js back end, I need to send an HTTP message to a REST endpoint. The endpoint requires some parameters that it will expect to find in the HTTP message. Some of the parameters are simple enough, just requiring a number or a string as an argument. But one of the parameters is to be "the raw binary file content being uploaded" and this has puzzled me. As far as I understand, the parameters need to be gathered together into a string to put in the body of the HTTP request; How do I add raw binary data to a string? Obviously, for it to be in the string, it cannot be raw binary data; it needs to be encoded into characters.
The endpoint in question is the Twitter media upload API. The "raw binary data" parameter is called media. Below is an incomplete code snippet showing the basic gist of what I've tried. Specifically, the line where I build the requestBody string. I don't believe it is anywhere near correct, because the endpoint is returning a "bad request" message.
var https = require("https");
var base64ImageData = /* (some base 64 string here) */;
var options = {
host: "api.twitter.com",
path: "/1.1/media/upload.json",
method: "POST",
headers: {
"Content-Type": "multipart/form-data"
}
};
var request = https.request(options, function(response) {});
var requestBody = "media_id=18283918294&media=" + Buffer.from(base64ImageData, "base64").toString("binary");
request.write(requestBody);
request.end();
Also worth noting, Twitter themselves note the following extremely confusing statement:
"When posting base64 encoded images, be sure to set the “Content-Transfer-Encoding: base64” on the image part of the message."
Source: https://developer.twitter.com/en/docs/media/upload-media/uploading-media/media-best-practices
That might be part of the answer to my question, but what I don't understand is: How do I apply different headers to different parts of the HTTP message? Because apparently, the image data needs to have a Content-Transfer-Encoding header of "base64" while the rest of the HTTP message does not...
How do I apply different headers to different parts of the HTTP message?
This is the point of the multipart/form-data content type. A multi-part message looks like this:
Content-Type: multipart/form-data; boundary=---foo---
---foo---
Content-Disposition: form-data; name="datafile1"; filename="r.gif"
Content-Transfer-Encoding: base64
Content-Type: image/gif
// data goes here
---foo---
Content-Disposition: form-data; name="datafile2"; filename="g.png"
Content-Transfer-Encoding: base64
Content-Type: image/png
// another file's data goes here
---foo---
You probably don't want to put all this together yourself. There are a bunch of good libraries for putting together complex POSTs. For example: https://www.npmjs.com/package/form-data

Umlauts broken when doing get request

I'm trying to query a webservice which answers with plain text. The text often has german umlauts in it. In the received stream the umlauts are broken. Any ideas what am I doing wrong?
Regards,
Torsten
Here is the sample code:
var request = require('request');
var uri = <anUriWithUserId>;
request(uri, {encoding: 'utf8','content-type': 'text/plain; charset=UTF-8'},
function (error, response, body)
{
console.log("encoding: " + response.headers['content-encoding']);
console.log("type: " + response.headers['content-type']);
console.log(body);
});
And the response:
encoding: undefined
type: text/plain
error=0
---
asin=
name=Eistee
detailname=Pfanner Der Gr�ne Tee, Zitrone - Kaktusfeige, 2,0 l
vendor=Hermann Pfanner Getr�nke GmbH, Lauterach, �sterreich
maincat=Getr�nke, Alkohol
When you set the encoding option in your request call, you advise the request module to decode the response body with this encoding. In this way you ignore the encoding used by the webservice, wich may or may not be utf-8. You need to find out wich encoding was used be the webservice and use that.
Depending on how complient the webservice you could also try to set the Accept-Charset: utf-8 header.
As your output shows, the webservice doesn't provide the used encoding in the Content-Type header, which is a bad habbit imho.
Sidenote: Content-Encoding isn't for charset, but for compression, gzip migh be a valid value for it.

Errors when trying NetSuite's Restlet interface: datain is null

I'm trying out Restlets for the first time and I am having trouble returning any data.
I've built a basic restlet and deployed it in NetSuite. The code is as follows:
function getRESTlet(dataIn) {
return nlapiLoadRecord(dataIn.recordtype, dataIn.id); // e.g recordtype="customer", id="769"
}
Using Chromes' REST Console application I've set up the following:
Request URI: https://rest.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=1&recordtype=customer&id=2409
Request Headers: NLAuth nlauth_account=123456,nlauth_email=email#emailaddy.com,nlauth_signature=password
Running it as a GET operation I return the following error:
error code: JS_EXCEPTION
error message:type
Followed by the following email:
Date & Time: 8/19/2013 2:48 pm
Execution Time: 0.06s
Script Usage: 0
Script: getRecord
Type: RESTlet
Function: getRESTlet
Error: SSS_MISSING_REQD_ARGUMENT
type
Stack Trace: getRESTlet(getCustomer.js:14)
restletwrapper(null$lib:3)
The customer record exists, the RestLet code is from the NetSuite help system, and I get an error email when the script fails so I know the deployment URL is good.
Any ideas on what I'm doing wrong?
--EDIT--
Changing my function signature to function getRESTlet(type,dataIn) resolves the type error, although now I get:
error code: UNEXPECTED_ERROR
error message:TypeError: Cannot read property "recordtype" from undefined (getCustomer.js#14)
I've also removed customer and id from the request URI and instead listed them in the Request Payload section of REST Console.
--Edit 2--
adding nlapiLogExecution('DEBUG', 'JSON.stringify(datain) is:', JSON.stringify(datain)); to the function is returning blank for the log entry. It appears that datain is null....
I had a similar issue that was resolved once I set the request header content-type to application/json.
The default content-type is text/plain which passes a stringified JSON object to the function and expects a string to be returned.
If you set the content-type to application/json or application/xml the 'datain' parameter will come in as a javascript object.
From the NetSuite Docs:
If users specify a content type other than JSON or TEXT, a 415 error
is returned with the following message:
Invalid content type. You can
only use application/json, application/xml or text/plain with
RESTlets.
If users provide data in a format different from specified
type, the following error is returned with one of the following
messages:
Error code = INVALID_RETURN_DATA_FORMAT Error message =
Invalid data format. You should return TEXT. Error message = Invalid
data format. You should return a JavaScript object.
To fix the error of
Error code = INVALID_RETURN_DATA_FORMAT Error message =
Invalid data format. You should return TEXT. Error message = Invalid
data format. You should return a JavaScript object.
You can supply a Content-type to the get specified get request of 'json'. Documentation would seem to indicate that you should specify "accepts" json, but for me only the content-type on a get made the request work.
I got this error: SSS_MISSING_REQD_ARGUMENT when trying to submit a transform record type that I had specified in camel case rather that all lower case... took me a day to work that out :(
changing the function to:
function getRESTlet(datain) {
return nlapiLoadRecord(datain.recordtype, datain.id); // e.g recordtype="customer", id="769"
}
resolves the issue. I thought I had tried without camelCase, but alas I did not.
So moral of the story is: datain is case sensitive!

Resources