I have a file represented in a byte[] and I want to add this as an attachment using Mailgun API. The problem is that I'm receiving an exception when I deploy it to Google App Engine. The exception is the next one:
com.sun.jersey.core.spi.component.ProviderFactory __getComponentProvider: The provider class, class com.sun.jersey.multipart.impl.MultiPartReaderClientSide, could not be instantiated. Processing will continue but the class will not be utilized (ProviderFactory.java:187)
java.lang.SecurityException: Unable to create temporary file
at java.io.File.checkAndCreate(File.java:2083)
at java.io.File.createTempFile(File.java:2198)
at java.io.File.createTempFile(File.java:2244)
The code used to send email is the next one:
Client client = Client.create ();
client.addFilter ( new HTTPBasicAuthFilter ( "api", "API-KEY" ) );
WebResource webResource = client.resource ( "MAILGUN-URL" );
FormDataMultiPart formData = new FormDataMultiPart ();
formData.field ( "from", "fromEmail" );
formData.field ( "to", "ToEmail" );
formData.field ( "subject", "Subject" );
formData.field ( "html", "Body" );
byte [] attachment = email.getAttachment();
if( attachment != null && attachment ().length > 0 )
{
FormDataBodyPart bodyPart = new FormDataBodyPart("Ticket", new ByteArrayInputStream ( attachment ),
MediaType.APPLICATION_OCTET_STREAM_TYPE);
formData.bodyPart(bodyPart);
}
ClientResponse clientResponse = webResource.type ( MediaType.MULTIPART_FORM_DATA )
.post ( ClientResponse.class, formData );
int status = clientResponse.getStatus ();
if ( status >= 400 )
{
throw new BadRequestException ( "Message couldn't be sent" );
}
else
{
return email;
}