2017-06-23 2 views
1

Ich versuche, Dateien mit elasticbean auf s3 hochzuladen. Es funktioniert lokal, sondern in der Produktion die nächsten Fehler:Kann Dateien in Produktion mit Jhipster in Elasticbean nicht nach s3 hochladen, aber funktioniert lokal

java.io.IOException: Permission denied 
at java.io.UnixFileSystem.createFileExclusively(Native Method) 
at java.io.File.createNewFile(File.java:1012) 
at com.ruano.erp.storage.FileSystemStorageService.store(FileSystemStorageService.java:73) 
at com.ruano.erp.web.rest.FileUploadResource.uploadFile(FileUploadResource.java:48) 
at com.ruano.erp.web.rest.FileUploadResource$$FastClassBySpringCGLIB$$3a8f87c4.invoke(<generated>) 
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) 
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 
at com.ryantenney.metrics.spring.TimedMethodInterceptor.invoke(TimedMethodInterceptor.java:48) 
at com.ryantenney.metrics.spring.TimedMethodInterceptor.invoke(TimedMethodInterceptor.java:34) 
at com.ryantenney.metrics.spring.AbstractMetricMethodInterceptor.invoke(AbstractMetricMethodInterceptor.java:59) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656) 
at com.ruano.erp.web.rest.FileUploadResource$$EnhancerBySpringCGLIB$$8db88d39.uploadFile(<generated>) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 

Der Upload-Code die nächste ist:

public String store(MultipartFile file, String folder, String id) { 
    try { 
     if (file.isEmpty()) { 
      throw new StorageException("Failed to store empty file " + file.getOriginalFilename()); 
     } 

     String extension = FilenameUtils.getExtension(file.getOriginalFilename()); 
     String newName = id+"."+extension; 

     AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials("KEY1", "KEY2")); 
     System.out.println("Uploading a new object to S3 from a file\n"); 
     String fileDestiny = "uploads/"+folder+"/"+newName; 

     File convFile = new File(file.getOriginalFilename()); 
     FileOutputStream fos = new FileOutputStream(convFile); 
     fos.write(file.getBytes()); 
     fos.close(); 

     s3client.putObject(new PutObjectRequest(s3Bucket, fileDestiny, convFile)); 

     return newName; 
    } catch (Exception e) { 
     throw new StorageException("Failed to store file " + file.getOriginalFilename(), e); 
    } 
} 

Nicht wirklich sicher, was das Problem ist, hat der Benutzer vollen Zugriff auf s3 und EC2 auch . Ich weiß nicht, ob die Funktion versucht, eine temporäre Datei in de Elasticbean Maschine zu machen und vielleicht hat es keinen Zugriff.

Antwort

1

Schließlich habe ich es, das Problem ist, dass Sie nicht im Dateisystem im ElasticBean schreiben können, so ersetzen ich diese Zeilen:

File convFile = new File(file.getOriginalFilename()); 
FileOutputStream fos = new FileOutputStream(convFile); 
fos.write(file.getBytes()); 
fos.close(); 

s3client.putObject(new PutObjectRequest(s3Bucket, fileDestiny, convFile)); 

mit diesem:

ObjectMetadata metadata = new ObjectMetadata(); 
metadata.setContentLength(file.getSize());     

s3client.putObject(new PutObjectRequest(s3Bucket, fileDestiny, file.getInputStream(), metadata)); 

Und endlich funktioniert!

Verwandte Themen