Can I use curl to upload an image on s3 to another server? - amazon-s3

I want to upload image on AWS S3 with curl to an external api server.
I know that if it's a local image I can specify it as below.
curl -X POST http://sample.com/api/ -F "upload=#1.jpg;type=image/jpeg"
Is it possible? how do we specify it?

Related

How to use signed url to access buckets in gcp

Goal: To be able to generate a link that allows the recipient to upload data to a specific folder in Google Cloud Storage regardless of them having a Google account (or any, for that matter). The link should authenticate them and give them access to the folder itself. This is intended to work in a very similar fashion as Drop Box where you can request files from users, and they get a URL to upload files to specified folders.
I've been able to follow the instructions from the GCP page and created a signed URL by running a gsutil command:
gsutil signurl -m PUT -d 1h -c application/octet-stream private_key.json gs://my_bucket/my_folder/
My expectation is to be able to copy the generated URL, and access it from a browser, to be welcomed into the GCS folder. But I keep getting this error:
<Error>
<Code>MalformedSecurityHeader</Code>
<Message>Your request has a malformed header.</Message>
<ParameterName>content-type</ParameterName>
<Details>Header was included in signedheaders, but not in the request.</Details>
</Error>
My gut tells me I'm either trying to use the signed URL in a way it's not meant to be used (maybe it should be part of a code that 'calls' that URL and lets the user access it via a UI). And I'm not a programmer, but more of an IT admin trying to automate file sharing/receiving. Or I'm doing something wrong; and thus my question here.
Any input you can give me would be greatly appreciated! Thanks in advance!

AWS Node SDK: How to generate a signed S3 getObject URL that doesn't include AccessKeyId

If one of my Selenium tests running in CircleCI fails, I upload a browser screenshot to S3 and print a signed getObject URL for it to the console, so that I can look up that screenshot quickly.
The problem is, S3.getSignedUrl adds my AWS AccessKeyId to the URL, and CircleCI is censoring it to ******************** since that value is in my environment variables, so the URL doesn't work:
https://s3.us-west-2.amazonaws.com/<bucket>/ERROR_3_reset_password_workflow_works.png
?AWSAccessKeyId=********************
&Expires=1612389785
&Signature=...
I don't see any options to output a different kind of URL in the getSignedUrl API docs. However, I noticed that when I open an image directly from the S3 console, the URL has a totally different form:
https://s3.us-west-2.amazonaws.com/<bucket>/ERROR_3_reset_password_workflow_works.png
?response-content-disposition=inline
&X-Amz-Security-Token=...
&X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Date=20210128T222508Z
&X-Amz-SignedHeaders=host
&X-Amz-Expires=300
&X-Amz-Credential=...
&X-Amz-Signature=...
Is there a way I can generate this type of URL with the S3 Node SDK? It doesn't use any values that CircleCI would censor, so it would work for what I'm trying to do.
I'm also looking into using CircleCI artifacts for the error screenshots, but I'd still like to understand how the S3 console is building the latter URL.
The Amazon S3 presignedURL examples here yield the format you're looking for. e.g.
[BUCKET]/[OBJECT]?X-Amz-Algorithm=[]&X-Amz-Content-Sha256=[]&X-Amz-Credential=[]&X-Amz-Date=[]&X-Amz-Expires=[]&X-Amz-Signature=[]&X-Amz-SignedHeaders=[]&x-amz-user-agent=[]
Note: These examples use V3 of the AWS SDK for JavaScript.

Laravel Retrieves Image from S3 with its URL

I need to retrieve an image from S3 and post it to Twitter using Laravel. The image is upload with Vapor (Vue js) and path URL stored in the database. Example URL (https://rippleflare-s3-dev.s3.amazonaws.com/7f87e5a4-f157-483e-8dcb-59a735194747). The image is accessible via the browser but when I try to get the image like this
Storage::disk('s3')->get($post->media_url)
Where the medial url is https://rippleflare-s3-dev.s3.amazonaws.com/7f87e5a4-f157-483e-8dcb-59a735194747 I get the error
Illuminate \ Contracts \ Filesystem \ FileNotFoundException
https://rippleflare-s3-dev.s3.amazonaws.com/7f87e5a4-f157-483e-8dcb-59a735194747
My question, how do I retrieve a file from S3 in Laravel using the file URL (path)
you can also define in a model to get your image path like this:
public function getMediaUrlAttribute()
{
return Storage::disk('s3')->url($this->media_url);
}
so it will gives your media url

Is it possible to download a file from AWS S3 bucket using postman?

Using Postman scripting, how to download the file from AWS S3 bucket
That's not possible,
Because in the browser download it's not just a direct 1 chunk
so it's creating a synchronous stream job which load chunk after another and such a system is not supported by postman

How can I see the image with CloudFront URL?

I have a bucket that has images uploaded with --acl public-read, so I can see the image when I use the s3 bucket link. However, when I use the CloudFront URL, it 307s. More strange is that my website is able to load the images, but not when I access it directly through the browser. How can I fix this? I am not even sure how to debug this.