I am trying to run a REST API on one port (8000) using django and consuming that API in an App running on port 9000 again using django.
My REST response is having an image field, now the problem is that i can not provide my desktop path in upload_to option in my API models and if i am giving the absolute path of API project in my App project index. Html, i get a browser error as "Not allowed to load resources from local path"
So i am having to create media folders with same name in both API and App projects and keeping image files in both and using only the file path from the REST response and rendering the image from App project itself.
Is there any way i can get away with this and consume the image from the Rest response only?
You need to convert image to base64 in server side then send those base64 string as response . Then consume this base64 string as response in calling api. Then use it accordingly either save in filesysyem or in database . But make sure to converse base 64 image string to bytes.
Related
I am trying to upload a file to the Shared Documents library of my SharePoint website. The files are of type PDF and HTML. I am running a Cold Fusion development environment and using CFHTTP commands to execute HTTP requests. I have been able push a POST command and a PUT command to the proper endpoints listed on this link below:
Link: https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#best-practices
I do not understand why but the first section that mentions the HTTP requests for creating an upload session is different than what was used in the example a little further. For my project, I am using the endpoint:
"/{variables.instance.microsoftGraphAPIURL}/drive/root:/{item-path}:/createUploadSession"
P.S. variables.instance.microsoftGraphAPIURL is a variable to a microsoft graph endpoint to our Sharepoint website
With better luck using PUT commands than POST commands for creating an Upload Session. I am able to receive an uploadURL, but the issue comes with trying to upload the file. For the file upload, I am trying to upload a file in the same directory with a file size of 114992 bytes. I keep getting "The Content-Range header length does not match the provided number of bytes." whenever I run my Put command to upload the file.
Thus, my Content-Range is "bytes 0-114991/114992" and my Content-Length is "114992". For the image below, I replaced the file with a pdf, but the original file was an HTML page at 114992 bytes. I want to use a resumable upload session to have one function for uploading image, HTML, and PDF files.
If anyone could tell me if there is an issue with my content headers or my upload session http request or anything else that is causing my issue, that would be amazing! Thank you.
I'm working on a react-native app witch contains some videos, and when I put in source the uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4', from google samples, it actually works, but if I try to put a uri for a video contained in my django media folder, the following error occur: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
How can I solve? Thank you
This is because AVFoundation is using byte range requests which is not supported by Django out of the box.
Add this to your middleware: https://github.com/AidenEllis/DjangoRangeMiddleware
Related: Byte Ranges in Django
I have a python script that take image using raspberry pi and update a JSON file with id and image URL, which is consumed by an iOS app.(Read Directly the JSON file)
I need a web service that parse the JSON and provide me with only image that is taken recently and return a JSON of new image and id.
so far I can put the code for the web service in the python script used for taking the image and access it using the URL : http://0.x.x.x:5000/application/api/v1.0/image
The above returns a JSON with old and new images and id's
Another problem is, I have to include the port number.
I tried Flask-RESTful for the above.
Is there any ready to use API's that can do this for me, or if I am to write my own web service what is the correct approach.
I have apache server running on the PI, how can I deploy the API and access it using the URL like ://PIAdress/application/Api/image
If there is a better approach please suggest.
Deploy Api to apache2 : example
have two app route : one to get full JSON - application/api/v1.0/image , second to get updated JSON - application/api/v1.0/image/'<'date'>'
get date from JSON and compare with the date from the app - (minus) 10 mins :
add to a list with JSON date that are greater than the compareDate
return jsonify(list) - for json of new image
I'm creating web services to make an Android app talk to a server.
I'm using Tomcat for the server and a JAX RS lib to convert data between Java objects and JSON during the transfers.
What I want is to be able to view the actual HTTP requests and responses the framework is creating.
A web browser (like Firefox with Firebug) won't do because I also need to check the request bodies generated by the Android app.
With the Servlet API I could intercept and get the request data with a filter, but not the response (I believe) after it was written by the framework.
Wireshark might be a solution (I'm trying it right now), but seems to be a bit to much. I need to worry about properly filtering my messages and didn't figure out yet how to get my HTTP messages properly formatted (plain text w/o the hexa content).
I wonder if there is a simpler way to do this from inside my application or from tomcat.
Try Tomcat's AccessLogValve. You can configure it to log incoming request headers as well as outgoing response headers. Here's an example:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_headers_access_log." suffix=".txt"
pattern="%t "%r" %s ||| %{Content-Length}o ||| %{User-Agent}i" />
Notice the %{xxx}o pattern - that's for response header. You might want to use it as %{X-JSON}o. Also notice the %{xxx}i pattern - that's for request headers.
Nest the <Valve/> element within a <Context/>, <Host/> or <Engine/> elements and you'll be all set.
I ended up using Wireshark with the following filter:
http.content_type == "application/json" || http.accept ==
"application/json"
To get the content decoded, right click on the json part of you package ("JavaScript Object Notation: application/json") > Copy > Bytes > Printable text only
I am sending get httpwebrequests to the facebook graph api and all was working fine till I deployed to production server and now module that expects html/xml response is not working and when tested url in internet explorer, the save file dialog pops up and the file needs to be saved.
Other modules also send requests to the facebook graph but just differ in the form of requests so not sure what is going on here.
Any ideas appreciated
Edit:
Let me try and rephrase this. On my production server the httpwebrequest was not returning the correct result. So to Test it I copied the url http://graph.facebook.com/pepsi which is an example, should return the profile info viewable in the browser. The server has internet explorer v8 and I am not sure why it tries to download the file instead of displaying it in the browser. this is what is happening in my code and when I make a request to a different part of the api, then it works in my app but not in the browser
Your question is not very clear. From what I gather, you want the display the JSON response in a browser. Instead, you are being asked to download a file by the browser.
Well, this is normal behaviour. The response you get from Facebook would most likely have a MIME type of application/json. Most newer web browsers display the text in the browser itself. Some browsers, however don't know how to handle this content type and just ask you to download the file.
You mentioned that your module expects an html/xml response. Try changing this to application/json.
You also said that it works in your app but not in your browser. I don't know what you're making, but generally you wouldn't show raw json to the user in a browser, right?