java


Upload file to S3 on EC2 instance - permission denied


So in my app, users will be able to upload their photos to S3 storage, then I will persist the returned Url to database.
The problem that I am having is that, when I deploy the app to my Elastic Beanstalk environment, I am not able to store photos to S3 storage anymore due to this error which I found in the catalina.out log:
java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1012)
at com.common.util.file.FileUtil.convert(FileUtil.java:17)
How can I set permission so that I can fix this bug?
[EDIT]
When I run the app on the localhost, then I will be able to upload the file into the S3 bucket. I used this sample code in this link as implementation template for uploading the file.
Here is the code that I use to convert a multipart file to a file:
public File convert(MultipartFile file) throws IOException {
File convFile = new File(file.getOriginalFilename());
convFile.createNewFile(); // Cause IOException
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
return convFile;
}
In your application, don't append the aws credentials. Create an IAM role which should have permission for AWS S3. When launching application using Elastic Beanstalk, attach this IAM role to an EC2 Instance.
Your application uses IAM role to authenticate AWS S3 to upload the images. It is a best practices to attach IAM role with specific permission for launching EC2 instance through AutoScaling group or Elastic Beanstalk or directly from EC2 dashboard.
The link to the sample code you provided uses ProfileCredentialsProvider, which vends AWSCredentials from the profile configuration file for the default profile (read more).
You'll need to either (1) copy the config file from your local machine to the EC2 instance or (2) use another method to supply AWS credentials to the SDK. See Working with AWS Credentials, for example.

Related Links

How to cumulate property placeholder?
facing org/dom4j/DocumentException
How can you wait until com.sun.codemodel.JCodeModel.build() has completed
get the max of R,G,B of one image by using programming [closed]
Replace html tags
java.lang.NoSuchMethodError: android.service.notification.StatusBarNotification.getKey
Enum versus lookup table
Why solr reindex data on highlighting?
How to prevent Eclipse use existing file tab when opening a new file
TestNG dataproviders with a #BeforeClass
Java preferred line break in a String
Netbeans crashes with error: Loadlibrary failed with error 126: the specified module could not be found
Is it a good practice to use 'd' when defining double literals in Java? [closed]
I need to make Scanner check to see if input is “quit”, and then if it's not, accept an integer
Closing only a single instance of JFrame?
allow app engine service account to edit calendar

Categories

HOME
xamarin
image
hive
deployment
keras
azure-data-factory
view
fme
youtube-dl
rsyslog
routes
amazon-ecs
mvvmcross
acquia
portia
paradox
cross-validation
gorm
metatrader4
vault
google-cloud-ml
visual-studio-cordova
quickfix
highlight.js
transformation
ab-testing
flux
swiftlint
accessor
su
maquette
newline
nat
phonegap
titanium-mobile
rotational-matrices
retina-display
space-complexity
espeak
mixture-model
event-driven
withings
c11
leading-zero
opshub
trim
broadcastreceiver
fedex
ncalc
grid.mvc
eigenvalue
avconv
pnotify
carrot
media-player
qtwebview
linode
vtigercrm
android-fonts
login-control
sigabrt
essence
make-install
freelancer.com-api
intellij-14
purge
android-listview
tableau-online
rake-task
tt-news
network-interface
applescript-objc
client-side-templating
eol
elliptic-curve
marmalade
ember-charts
app42
prettify
ivyde
dir
excel-2003
ora-00911
cos
dataadapter
yui-compressor
plasma
enterprisedb
newtonscript
windows-phone-7.1.1
bigcouch
stage
mod-auth
horizontal-accordion
appender
recent-documents
appendto
sql-server-profiler
visitor-statistic
gallio
mozilla-prism
perfect-hash
private-members
ajax-forms

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App