When I send the following query
http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=coffee%20New%20York%20NY
using c# WebClient.DownloadString function or ordinary web browser
I get JSON data which is different from data for the same query using JavaScript and
Google AJAX Search API.
From REST service I get the following url field
http://www.google.com/maps/place?source003duds0026q003dcoffee0026cid003d13245583795745066822
but from JavaScript query I get this url field
http://www.google.com/maps/place?source=uds&q=coffee&cid=13245583795745066822
The problem with REST service answer is that the url it gives points
to a web page with error message "We currently do not support the location".
What am I doing wrong?
It looks like either you are decoding the URI from the REST request incorrectly, or Google is ending it wrong. The = are being sent or parsed as 003d and the & as 0026
EDIT : After trying that link I see they return the links, in the JSON, with the '=' and '&' encoded, the JavaScript must be replacing those characters for you automatically. You could do a simple String replace on "003d" and "0026" - although I'm not sure that will cover every use case.
I resolved this by parsing JSON data with Json.NET library http://json.codeplex.com/
Related
I have deployed an AWS Lambda function, written in Python, and AWS API Gateway structure to cause POST requests to an API endpoint to be redirected to my function. I want to upload a PDF document to my function and have it store the document in a S3 bucket. The problem I have is that the payload of any POST request to my API is being UTF-8 encoded. I don't want that but can't figure out the magic mojo to disable encoding of the request payload.
I am testing using curl, with the following command line:
curl -XPOST https://xxxxxxxxxx.execute-api.us-west-1.amazonaws.com/test -H 'content-type: application/pdf' --data-binary #document.pdf
UPDATE: I just found the following article describing how API Gateway and Lambda support uploading binary data:
https://aws.amazon.com/blogs/compute/handling-binary-data-using-amazon-api-gateway-http-apis/
This article suggests that all of the complexities that I discussed in the initial formation of my question (still provided below) should not be necessary. All I should need to do to upload binary content to my Lambda function is insure that my request includes an appropriate Content-Type header. I was already doing that, but I massaged my Curl command a bit (modified above) to define my request in exactly the way that is done in this article. I still get UTF-8 encoded data and NOT base-64 encoded data. I tried uploading a jpeg file rather than a PDF so I was doing exactly what was done in the article. Still no love. I don't get it. This article demonstrates exactly what I'm doing. But I don't get the result it suggests I should. Ggggrrrr.
ORIGINAL POST:
I am using Terraform to define my deployment. I want to cause the PDF to not be encoded/mangled at all. This is my first time using API Gateway, and I'm obviously missing some bit of config. The one thing I'm doing specifically right now to say that I want incoming payloads to be treated as binary is via the binary_media_types argument to my API definition in Terraform:
resource aws_api_gateway_rest_api proxy {
...
binary_media_types = [
"application/pdf",
"application/octet-stream",
"*/*"
]
This sets the Binary Media Types configuration associated with the API I've defined. I've confirmed via the AWS Console that this setting is having the desired effect...I can see these types in the console. I should need just the first item in the list, but I've added the others while I try to figure out the problem here. By adding that wildcard item, I believe that it shouldn't matter what the incoming Content-Type is...all payloads should be being treated as binary.
The other bit of config that I know about that might be important is the "integration contentHandling property". Here is the key bit of AWS docs that seems to explain all this:
I think the case that applies to me here is the one I've highlighted, per what I say above. This says to me that I shouldn't need to do anything else, per the "unspecified" value in the table for "contentHandling. I've tried setting the "contentHandling" argument on the integration record of my Terraform config, like this:
resource aws_api_gateway_integration proxy {
...
passthrough_behavior = "WHEN_NO_MATCH"
content_handling = "CONVERT_TO_BINARY"
}
I first tried only specifying the content_handling value. I've also tried setting that value to "CONVERT_TO_TEXT", hoping to then get base64-encoded data. Neither of these has any effect. I've tried adding the passthrough_behavior value as shown. I've also tried replacing "WHEN_NO_MATCH" with "WHEN_NO_TEMPLATES". Nothing I do changes the behavior. I haven't been able to figure out where these settings would show up in the AWS console. If I knew they were necessary, I'd explore this further. But I don't think I need to set these.
What am I missing? How can I POST a PDF document to my AWS Lambda function through API Gateway and have the payload of the request not be converted in any way? TIA!
NOTE: I am aware of this Q/A: PDF Uploaded via AWS API Gateway getting corrupted. The answer there doesn't apply to me, as I need to avoid having to form-encode the upload. The client code that will eventually be doing the upload is set in stone and sends a POST request with a payload that is just the bytes of the PDF.
I'm using Django and DRF, and I have a view that retrieves a Binary File (Using BinaryFileRenderer) from an external API. This external API brings the binary data from S3.
I need to mock this call so I could test the logic by isolating the API call, but every time I tried I received some error. For example, I tried creating a MockFile class with content, mime_type, and name fields. And I started to receive the error "AssertionError: renderer returned Unicode, and did not specify a charset value."
After some investigation, apparently, it was expecting some kind of Renderer file. But this is when I got confused. Because Python is dynamic, I'm never sure what kind of file I received and I'm not sure how I can mock the binary file I'm receiving.
Anyone can point me to how correctly mock this binary file?
Good morning. I am new to logic apps and I am trying to figure out how I can trigger the execution based on a GET URL with three parameters. All the examples I've found on Google show the URL being generated once the JSON and relative path is entered, but that's not happening for me. Perhaps it's because I am creating the logic app in VS.
Here's what my "When a HTTP request is received" step looks like in the logic app.
I also tried removing the JSON and just using the parameters to pass the values to the function, as shown below. I'm just not sure the best way to do this.
All I really need to do is get the three parameters into the logic app so I can perform a function call with the parameters. Any suggestions would be greatly appreciated!
Why is my HTTP request URL not being generated for a Logic App?
You need to click save, and then the url will be automatically generated for the When a HTTP request is received trigger:
You can use this expression to accept values through GET parameters:
triggerOutputs()['queries']['parameter-name']
For example:
Noteļ¼
Queries need to pass parameters in the form of json.
I have an Azure Mobile service with a .Net back end.
In the backend the data object use proper case. for example, MemberNumber.
In the azure client the view models use pascal case memberNumber.
I am using a library that creates an ODATA request and I get:
The query specified in the URI is not valid. Could not find a property named 'memberNumber' on type 'arenaapi.DataObjects.Members'.
That happens with this get:
/tables/members?%24inlinecount=allpages&%24orderby=memberNumber
If I change that the MemberNumber it works.
However, also, if I change the request to:
/tables/members?%24inlinecount=allpages&$orderby=memberNumber
It also works. It seems that the model binding parser is working differently if the $ is encoded or not.
Is there any way I can fix this server side so the encoded request won't return a 400 without changing the memberNumber to MemberNumber?
All the other stuff, posting, patching, etc is properly binding the pascal cased JSON post to proper cased c# data objects.
On IE when i try to browse the rest apis, i am getting a application/json response instead of api (text/html) response (Returns html response on firefox). I am using django restframework 2.2.5 for this purpose.
I read through the documnets and understood that in order to overcome the problem of broken headers for IE we need to use TemplateHTMLRenderer explicitly in the view, so i have added the following to the class definition of my view but still i am getting a json response. Am i not doing it correctly or i am missing something else?
class CustomReports(generics.GenericAPIView):
`renderer_classes = (renderers.TemplateHTMLRenderer)`
Can you please help in fix the problem so that i get html response in case of IE as well?
Which version of IE are you using? I believe newer versions of IE should send correct Accept headers.
I probably wouldn't bother trying to fix things up to work around IE's broken behavior, but instead just make sure that you're including format suffixes in your urls. Then you can simply use the .api suffix to see the browseable API, or the .json suffix to see the plain json.
Eg instead of http://127.0.0.1:8000/api-root/, use http://127.0.0.1:8000/api-root/.api.