Sending canvas object with restfull api in django - json

I am using django as my backend and I am using restful api to communicate with react js frontend. I have created a pdf invoice with canvas and I was able to send it via mail system of django. But I also want to show the pdf on web page. So I need to send it to front end via api url. I tried to send it as response but I got the error:
Object of type Canvas is not JSON serializable
The code that I wrote to send pdf:
return Response(c, status=status.HTTP_200_OK)
c stands for the canvas object which is a pdf
Is there a solution of this? Or how do I send the pdf to the front end.
Thank you

I think you can send the static url(eg. 127:.0.0.1:8000/static/yourfile.pdf) for the pdf, which will be rendered by the browser. And you can add a button in your react frontend which will redirect to the pdf url.

Related

How to send form as json in 11ty

I'm trying to send data from 11ty to my directus headless CMS.
The problem here is Directus only accepts json data.
No problem to send the data with regular website, but as 11ty is a static site generator, I can't find the way to send the data as json instead of form, because I can only use javascript for receiving data.
Thanks!
On your form, why not use JavaScript to handle the form submission and then use fetch() to hit the CMS? Basically, this is something you handle in client-side JS, via your generated site.
As I recall, Directus provides a collection endpoint, i.e. /items/contacts where you can directly POST your form submission.

How to call third party site's json api from shopify custom app

I created custom app in shopify admin. But I don't know how to call thirdparty site json api with that app. Can anyone help me about this.
In your App, set up the App Proxy. That is an endpoint in your App, GET or POST that you can receive data at. Shopify will call that endpoint with security so you know inside your App the call is a good one. Since you are inside your secure App, this is the place where you can call your third-party API to get data. Once that call completes, you can return JSON to Shopify.
In Shopify theme, the call is /apps/my_end_point with data. Shopify mangles all that, and sends it to your Proxy. So your proxy get data from the front-end, and you can then safely call your APIs, and return JSON to Shopify.
Simple and elegant pattern of use you have to use. There really is no other way to do it securely.

API call directly from Design Automation Activity

I am trying to follow DA tutorial to extract data from CAD file and post the data to a web api. Probably I can extract and save a data file in OSS( or somewhere temporarily, I haven't figured out yet), and use my web app to read this file before sending the api request. Instead of this double handling, is it legal to call API directly from Activities? Same like a plug-in in laptop, it programs a local file and then sends a HTTP call.
Thank you.
is it legal to call API directly from Activities? Same like a plug-in in laptop, it programs a local file and then sends a HTTP call.
Currently it is not possible to send Http requests from within Appbundle code, this is something our Engineering team researching.

Box file service file actions

When building a File Service App, how can my app send data back to Box? I've been reading about the callback urls to send data to my app, but I don't see how my app can send data back that will update user's Box account, like there is with the Content API.
The token you get from Box in the callback is valid for you to call APIs. Just use it in the header, and you'll be able to call APIs

How to handle cross domain iframe file upload json response?

I'm building an files upload API.
Basically, the user will have to POST the files with his/her api_key + signature to my web service. Then my web service replies back with a JSON response. I'm wondering how can this process work asynchronously?
Assuming that the user POST the request in a form setting the target to an iframe. The JSON response will be sent back to the user on his/her iframe with content type set as "text/html". It is set as "text/html" instead of "application/json" because I want to avoid having a "pre" tag injected by the browser around the JSON response. Anyway, how does the user read that JSON response if the iframe and the parent window have different domain? There is going to be a cross domain policy issue.
Dynamically create "script" tag plus JSONP won't work in this case because I need to POST in order to upload. JSONP only works with GET requests.
Take a look at the 'Upload' example here. It uses Cross Domain messaging to pass the message back to the uploading page, and uses easyXDM to support all browsers.
This post explains how it all works!
Because of Same Origin Policy, browsers wont allow JavaScript in the main frame reading/accessing whatever content in iframe from another domain. In this case, the users will have to use easyXDM or create their own proxy -- by proxy here i mean users will have to write some code on their backend that can communicate with your API such that a post request will go directly to your server, and a get response will get from their own proxy.