Google Cloud Storage upload using link - google-cloud-platform

I can successfully upload file in the Google JSON API using [Objects: insert] by passing binary file content. I was curious if there is a way to upload by passing an open link in a JSON payload allowing GCP to retrieve the file. Thanks!

It seems Signed URLs can help you do this.
you can check here
https://cloud.google.com/storage/docs/access-control/signed-urls

Related

Django google app engine No such file or directory

I have a Django 2.x with python 3.6 site in Google Cloud, the app is in app engine flex. (my first app :)
My app has an upload page, where I am asking the user upload a JSON file (that is never kept in the site), what I do is open it and generate another file from it
I know that django depending on the size of the file it goes into memory but I was never able to use this functionality, so what I did in local env, was creating a folder that I called, temp_reports, so I created the files here, uploaded them into a bucket and then deleted them, from temp_reports.
So I was thinking, as the site is already in gcloud, if I can directly create these files into the bucket? or do I still need to generate them in the site and then upload them?
Now if it is from my site I keep getting the following error:
Exception Value:
[Errno 2] No such file or directory: '/home/vmagent/app/temp_reports/file_516A3E1B80334372ADB440681BB5F030.xlsx
I had in my app.yaml
handlers:
- url: /temp_reports
static_dir: temp_reports
Is there something I am missing? in order to use temp_reports?
Or how can I create a file directly into my bucket?
You can certainly use the Storage Bucket without having to upload the file manually. This can be done by Google Cloud Storage client library (Preferred Method) . It allows you to store and retrieve data directly from the Storage Bucket. Secondly, you can use Cloud Storage API to do the same functionality but requires more efforts to set it up.
You want to use the upload_from_string method from google.cloud.storage.blob.Blob.
upload_from_string(data, content_type='text/plain', client=None,
predefined_acl=None)
So to create a text file directly on the bucket you could do this:
storage_client = storage.Client()
bucket = storage_client.get_bucket(‘mybucket’)
blob = bucket.blob(‘mytextfile.txt’)
blob.upload_from_string('Text file contents', content_type='text/plain')
For more information you can refer to the following page:
https://googleapis.github.io/google-cloud-python/latest/storage/blobs.html#google.cloud.storage.blob.Blob.upload_from_string

How to upload file (pdf) using raw in Postman?

I am trying to automate attaching a form data pdf file in Postman. Can it be done using raw in Postman? Please assist. Thank you!
Files can only be uploaded using the 'binary' and 'form-data' option. Postman considers raw data as a string.
Have a look at the documentation for a complete list of options Postman provides: https://www.getpostman.com/docs/postman/sending_api_requests/requests
You can choose the form-data upload. When adding a new form field, you can change the type of the field to "File". In Postman's current version (7.8) you have to leave the entry line and then move the mouse over the newly created entry to see this option.

Django application to upload videos on S3 using boto3

I am new to Django and want to develop an application to upload videos on AWS S3 using Boto3.
Please guide me step-by-step on how to implement this?
As I am new it's little hard for me to understand.
Earlier I tried and created one Form with form.FileField() and it returns File Object but that fileobject I am not able to upload using boto3 as upload_fileObj method must require read implemented as a rb.
Thanks in advance and waiting for guidance.
You should first create a file from your File Object in /tmp/ directory.
After that you can use that file path to upload using upload_file
once you are sure that the file is uploaded successfully you can delete that file from /tmp/ directory.
Incase, file is not being properly uploaded you can retry it also.

Add an image to an API with Postman-Chrome

I am working with a visual search service API. The engine should allow upload of images to the database and their identification when the same image is queried.
I am using the "PostMan" add-on to chrome for this purpose.
Example:
- The engine API Link: {API_URL}
- to add a new image should add: /refimages/
Now in the documentation it says we should somehow provide these information:
{
"refImgId":"img0093984",
"score":3.48
}
as JSON file and the
Image URL
I am not sure I know how I can provide these information to in Postman. I cannot find where the image URL can be provided. Do you have any ideas? Thanks for suggestions.
The file should be of format: multipart/form-data
If you look to the far right you can see "Text" change that to File, now you can choose a file to upload/post

python upload image from a url to google drive api

For my Python app,I had completed the basic settings to interact with google drive api and found it working by a test upload of a CSV file. Now I need to upload an image from a url to a newly created folder named 'myappname' in Google Drive.
Thanks in advance
For now, there is no way you can directly upload file from url. There are two workaround I can think of
Download file and upload it back using Files.insert()
Use Save to Drive button
Using save to Drive button requires user interaction to click the button which might not be the one you want. In that case, downloading and uploading is the only way I can think of.