How to show image in AWS S3 with blocking public access for laravel - php

two web(EC2 and PC)
use laravel(php)
AWS S3 with blocking public access
public function showimg($id)
{
return Storage::disk('s3.private')->response('test/'.$id);
}
This code with AWS EC2(has dns and ssl) will show image.But in PC will not.
.env for s3 setting are the same
two BUCKET setting are the same

Related

Twilio Whatsapp API - Specify Local Image Path in PHP Server

Looking for a way to specify image path that's stored in local server in Whatsapp twilio api. I can send image via api using hosted image links but having difficulty specifying local file path. Can you help?
<?php
// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("whatsapp:+15017122661", // to
[
"mediaUrl" => ["https://images.unsplash.com/photo-1545093149-618ce3bcf49d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=668&q=80"],
"from" => "whatsapp:+14155238886"
]
);
print($message->sid);
?>
In short, I want to know whether i can attach local image file to the message using the mediaURL attribute.
When Twilio processes your request to send an MMS or a WhatsApp Message with an mediaUrl, Twilio will retrieve the file from the Media URL that you provided. However, Twilio cannot access your localhost network.
First, make sure the media files are served by your web server.
Then, during development, you can tunnel your localhost network to the public internet using tools like ngrok. You'd run a command like this:
ngrok http https://localhost:5000
https://localhost:5000 should be replaced with the localhost URL to the web server serving your media locally.
The output will display the public Forwarding URL created by ngrok. Any HTTP request to this Forwarding URL will be forwarded to your application listening to https://localhost:5000. Use this public Forwarding URL with the path to your file, as your Media URL and Twilio should be able to retrieve it and sent it as an MMS.
When you deploy your application to a web server that is publicly accessible, you won't need a tunnel anymore, but can point to the public domain of where your media is served.
Note, if you don't want your media to be publicly accessible, you can secure your application by validating the HTTP request originates from Twilio.
Alternatively, you can upload your media to a storage service like AWS S3, Azure Storage, Google Cloud Storage, etc.
Make sure the media is publicly accessible and then use the public URL of the uploaded media.

Connection Refused error in Amazon AWS EC2 api call

"org.apache.http.conn.HttpHostConnectException: Connection to http://myurl.amazonaws.com Connection refused."
Here I am using a web service uploaded in Amazon AWS EC2 server, which is used to upload a video. But on the start it throws an error of Connection refused. Api call is from Android App(method used is httpclienturlconnection & HttpClient, org.apache.httpcomponents gradle for it). One another error also occurs that -> "Value org.apache.http.conn.HttpHostConnectException of type java.lang.String cannot be converted to JSONObject". It just simply works in swift(IOS) but it gets stuck in Andorid(JAVA Base) with the same web service. Thank you in Advance.

Deploy a Laravel App on AWS EB - inconsistent Sessions

I try to Deploy a Laravel App via AWS ElasticBeanstalk with Classic Load Balancer.
I store my laravel sessions in a database on an AWS RDS, the connection is working fine.
It is all working fine, except that every request is generating a new session.
In my .ebextensions I added therefore, session stickiness
option_settings:
aws:elasticbeanstalk:environment:process:default:
Port: '80'
Protocol: HTTP
aws:elb:listener:443:
ListenerProtocol: HTTPS
SSLCertificateId: my_ssl_arn...
InstancePort: 80
InstanceProtocol: HTTP
aws:elb:listener:80:
ListenerEnabled: true
aws:elb:policies:sessionstickiness:
CookieName: laravel_session
LoadBalancerPorts: 443, 80
In the App itself, i force via middleware to use https://
Its Laravel Version 5.5, in the TrustProxiesMiddleware i added:
protected $proxies = '**';
I just don't understand where the problem is and tried already a lot of different settings.
Did anyone get experience with that? What do I oversee here?

how to coneect to amaonz RDS localhost from my pc

i try to connect to my amazon RDS server in my home pc
but i cant to do that i get a error:
this is my code:
$mysqli = new mysqli('server.eu-west-1.rds.amazonaws.com:3306',
'serverName', 'serverPassword', 'serverTable');
$mysqli->set_charset('utf8'); var_dump($mysqli);
but i get an error:
in my SecurityGroup at amazon:
There are multiple reasons which could lead to this issue. Few of them are
Placing RDS instance in private subnet
Security group restrictions
NACL restrictions
In your case, its most likely you have attached a security group to amazon RDS instance which is not accessible from outside. Also make sure you have enabled public access to your database instance in RDS.
i fix that
looks at DB Instances in RDS:
dont forget to do yes for Publicly Accessible :)
enter image description here

canot establish connection to localhost through facebook application

i have created a new Facebook application and i used the following url as canvas url http://localhost/my_app/
my code works perfectly on localhost, but when i try to cal my application using the following url : apps.facebook.com/leenaaps its displays the following error:
Unable to connect
Firefox can't establish a connection to the server at localhost
what could be the problem exactly?
You most likely do not have a local webserver running. If you do, it might be possible that Facebook uses https:// but you did not configure/enable SSL.
localhost is resolved to ip 127.0.0.1 and this is the local loopback address whcih means it is not routable and cannot be accessed from the internet, So you cannot use it in your canvas url.
You have to use a valid and active domain name like domain.com. If you don't have a public web server you may use some DDNS service, google it some are free

Categories