Enregistrer des pièces jointes de formulaire dans Azure
@Override
// Save the submitted form attachment in azure and return its url
public String saveFormAttachmentinAzure(InputStream attachmentStream, String fileName, String contentType) {
logger.debug("Saving " + fileName + " form attachment in azure ");
String sasToken = azurePortalConfigurationService.getSASToken();
String storageURI = azurePortalConfigurationService.getStorageURI();
logger.debug("The SAS Token is " + sasToken);
logger.debug("The Storage URL is " + storageURI);
int timeout = 5;
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout * 1000).build();
org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
UUID uuid = UUID.randomUUID();
String putRequestURL = storageURI + uuid.toString();
putRequestURL = putRequestURL + sasToken;
System.out.println("The put Request " + putRequestURL);
HttpPut httpPut = new HttpPut(putRequestURL);
httpPut.addHeader("x-ms-blob-type", "BlockBlob");
try {
InputStreamEntity ies = new InputStreamEntity(attachmentStream, attachmentStream.available());
httpPut.setEntity(ies);
CloseableHttpResponse response = httpClient.execute(httpPut);
logger.debug("Response code " + response.getStatusLine().getStatusCode());
logger.debug("Added file attachment " + response.getStatusLine().getStatusCode() + " uuid " + uuid.toString() + " " + response.getStatusLine().getReasonPhrase());
if (response.getStatusLine().getStatusCode() == 201) {
return putRequestURL;
}
} catch (Exception e) {
logger.error("Error: " + e.getMessage());
throw new RuntimeException(e);
}
return null;
}
Enregistrer des données de formulaire dans Azure
@Override
public String saveFormDatainAzure(String formData, String contentType) {
String sasToken = azurePortalConfigurationService.getSASToken();
String storageURI = azurePortalConfigurationService.getStorageURI();
logger.debug("The SAS Token is " + sasToken);
logger.debug("The Storage URL is " + storageURI);
logger.debug("The form data is " + formData);
int timeout = 5;
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout * 1000).build();
org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
UUID uuid = UUID.randomUUID();
String putRequestURL = storageURI + uuid.toString();
putRequestURL = putRequestURL + sasToken;
logger.debug("The put Request " + putRequestURL);
HttpPut httpPut = new HttpPut(putRequestURL);
httpPut.addHeader("x-ms-blob-type", "BlockBlob");
httpPut.addHeader("Content-Type", contentType);
try {
httpPut.setEntity(new StringEntity(formData));
CloseableHttpResponse response = httpClient.execute(httpPut);
logger.debug("Response code " + response.getStatusLine().getStatusCode());
System.out.println("The response code is " + response.getStatusLine().getStatusCode() + "uuid " + uuid.toString());
if (response.getStatusLine().getStatusCode() == 201) {
return uuid.toString();
}
} catch (IOException e) {
logger.error("Error: " + e.getMessage());
throw new RuntimeException(e);
}
return null;
}