Creating nodes with image via REST - web-services

I have searched all the docs but have still no clue how to create a node in Drupal 7 that contains a image field. I create the node(s) via REST Services and everything works except the image thing.
Do i have to post the image data with the post request that creates the node? (as multipart??) Or should i upload the image via ftp and link (and if, how?) to it?
maybe someone else has done a similar job.. thanks forward..

In Rails 2.3.x you had to define a form as multipart to make file uploads work, so I think you need to create the Node as multipart aswell. Just a guess from my side, since I don't have any experience with Drupal at all.

Related

Python Flask app on EC2 AWS, host by apache2

I'm trying to build a Flask APP, which includes two webpages. The first one allows users to upload an image, after which the server will take the image input and make predictions from CNN and generate some image results. For the first page and from the server end, they both work well. The user upload and image generation are successful. However, the second page won't load the newly generated images. The page shows as bellow:
The second webpage
Two issues could be possibly related to this:
Permission issue? I set the permission of this app folder and subfolders to 777, although the uploaded images and newly generated images are not. Please see the below image for details of these image permissions.
ls -la for all images to be shown
Even The pink ones are either uploaded(the first one) or newly generated (the rest two), while green ones are "shutil" copied from another folder. As green images inherit the previous permissions, it should display, but why does it not?
BTW, I also tried the solution here, but it still doesn't work.
Am I on the right track to solve this? Thanks in advance for any help.
Yanyang
Have you inspected to validate that the image path its using as the src is correct? This would be your first step to validate the application is correct.
After that try validating any error logs that may indicate a local file error, this would depend on the web server software you're using.

Simple file upload to Django via HTTP request

I'm really confused with the process of uploading a file (image or pdf in my case) to a Django app programmatically (via HTTP POST or PUT request). I've read the doc but I must admit it hasn't helped me get through. The most confusing part to me is the template (and form) : why do I need to specify a template and form in the view ?
I just want to send a file to a directory, and I'd like to know what exactly is needed in order to do so on the Django part as well as on the request part (content-type... ?)
I'd be really grateful to anyone able to show me some direction here..
You don't say what doc you're reading, so it's hard for us to tell what you mean. But if you're planning on doing a programmatic upload, you don't need a template, of course. You do however need some code that accepts the POST and processes the upload: you can do that with a form, or simply access the data in request.FILES and do what you want with it yourself.
Edit It's true that that page doesn't make any reference to uploading programmatically, because most people's use cases are uploading through the browser, via a form. But the page does explain how to handle uploaded files, which is the only bit that you need.

How can I modify django-postman to allow sending of attachments?

It doesn't seem as if django-postman supports attachments so I'm trying to add attachment support. I'm thinking of doing it by creating another set of models that will refer to a postman message and then update the views/templates accordingly but it will be a fair amount of work.
Django-postman isn't exactly an SMTP based messaging system so attachments would need to implemented through a different module. I think you should check some of the django file management projects
https://www.djangopackages.com/grids/g/file-managers/
One of the simplest idea I can think of is to save files in some kind of hashed name and associate these names with the postman message .
I think this would be a good addition to postman itself.
So I ended up figuring out how to do this on my own but it could use some work. The additional constraint we had to work with was that we were already using jQuery File Upload to upload files via AJAX so we needed a way to integrate the two.
Our solution was to create an app that contained a new model and a custom reply form that made it relatively easy to link the two together.
I wrote it up at http://dangoldin.com/2013/05/17/adding-attachments-to-django-postman/ and hope it helps others.

django sorl-thumbnail json

I am using Sorl-Thumbnail to generate thumbnails within pages via template tags.
This all works perfectly fine.
However I have now added a store locator function to the site which feeds into my Google Maps JS via JSON.
In the infowindow popups I would like to put a tiny image of the storefront.
So I need to create another size of thumbnail and I need to include the URL for this within my JSON.
It seemed initially that Sorl doesnt support this due to its requirement for Tags within a page.
I have looked at the low level API version "get_thumbnail" and have tried to implement this within my Model without much luck so far.
I have no problem with my JSON and serialisation, just getting the thumbnail generated and into the model prior to this.
Has anyone had any experience with this scenario previously?
Cheers
Kev

Need help setting up django-filetransfers

My setup is: Django 1.3/Python 2.7.2/Win Server 2008 R2/IIS 7.5/MS SQL Server 2008 R2. I am developing an application whose main function is to analyze uploaded files and produce a report.
Reading over the documentation for django-filetransfers, I believe this is a solution to a problem I've been trying to solve for a while (i.e. form-based file uploads completely block all Django responses until the file-transfer finishes...horror for even moderate-sized files).
The documentation talks about piping uploads to S3 or Blobstore, and that might be what I end up doing eventually, but during development I thought maybe I could just set up my own "poor-man's S3" on a server that I control. This would basically just be another Django instance (or possibly a simple ASP.NET app) whose sole purpose is to receive uploaded files. This sounds like it should be possible with django-filetransfers and would solve the problem of Django responsiveness (???).
But I am missing some bits of understanding how this works in general, as well as some specifics. Maybe an example will help: let's say I have MyMainDjangoServer and MyFileUploadServer. MyMainDjangoServer will serve the views, including the upload form. MyFileUploadServer will "catch" the uploaded files. My questions/confusion are as follows:
My upload form will contain additional fields beyond just the file(s)...do I understand correctly that MyMainDjangoServer will somehow still get that form data, minus the file data (basically: request.POST), and the file data gets shunted over to MyFileUploadServer? How does this work? Will MyMainDjangoServer still block during the upload to MyFileUploadServer?
I assume that what I would need to do on MyFileUploadServer is have a view/URL that handles the form request and sucks out the request.FILES data. What else needs to happen? What happens to the rest of the form data?
How would I set up my settings.py for this scenario? The django-filetransfers examples seem to assume either S3 or GAE/Blobstore but maybe I am missing some basics.
Any advice/answers appreciated...this is a confusing and frustrating area of Django for me.
"MyMainDjangoServer will somehow still get that form data, minus the file data (basically: request.POST), and the file data gets shunted over to MyFileUploadServer? How does this work? Will MyMainDjangoServer still block during the upload to MyFileUploadServer?"
I know the GAE Blobstore, presumably S3 as well, handles this by requiring you to give it a success_url. In your case that would be the url on MyMainDjangoServer where your file receiving view on MyFileUploadServer would re-post the non-files form data to once the upload is complete.
Have a look at the create_upload_url method here: https://developers.google.com/appengine/docs/python/blobstore/functions
You need to recreate this functionality in some form (see below).
"How would I set up my settings.py for this scenario?"
You'd need to create your own filetransfers backend which would be a file with a prepare_upload function in it.
You can see the App Engine one here:
https://github.com/django-nonrel/djangoappengine/blob/develop/storage.py
The prepare_upload method just wraps the GAE create_upload_url method mentioned above.
So in your settings.py you'd have something like:
PREPARE_UPLOAD_BACKEND = 'myapp.filetransfers_backend.prepare_upload'
(i.e. the import path to your prepare_upload function)
For the rest you can start with the ones provided by filetransfers already:
SERVE_FILE_BACKEND = 'filetransfers.backends.url.serve_file'
# if you need it:
PUBLIC_DOWNLOAD_URL_BACKEND = 'filetransfers.backends.url.public_download_url'
These rely on the file_field.url being set (see Django docs) and since your files will be on a separate server you probably need to look into writing a custom storage backend for Django too. (the S3 and GAE cases assume you're using the custom Django storage backends from here)