in PluginsAndFeatures/azure-toolkit-for-intellij/src/main/java/com/microsoft/intellij/helpers/storage/BlobExplorerFileEditor.java [681:784]
private void uploadFile(final String path, final File selectedFile) {
final AzureString title = AzureOperationBundle.title("blob.upload_blob.file|container", selectedFile, blobContainer.getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
try {
final BlobDirectory blobDirectory = directoryQueue.peekLast();
final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(selectedFile));
progressIndicator.setIndeterminate(false);
progressIndicator.setText("Uploading blob...");
progressIndicator.setText2("0% uploaded");
try {
final CallableSingleArg<Void, Long> callable = new CallableSingleArg<Void, Long>() {
@Override
public Void call(Long uploadedBytes) throws Exception {
double progress = ((double) uploadedBytes) / selectedFile.length();
progressIndicator.setFraction(progress);
progressIndicator.setText2(String.format("%s%% uploaded", (int) (progress * 100)));
return null;
}
};
Future<Void> future = ApplicationManager.getApplication().executeOnPooledThread(new Callable<Void>() {
@Override
public Void call() throws AzureCmdException {
try {
StorageClientSDKManager.getManager().uploadBlobFileContent(
connectionString,
blobContainer,
path,
bufferedInputStream,
callable,
1024 * 1024,
selectedFile.length());
} finally {
try {
bufferedInputStream.close();
} catch (IOException ignored) {
}
}
return null;
}
});
while (!future.isDone()) {
Thread.sleep(500);
progressIndicator.checkCanceled();
if (progressIndicator.isCanceled()) {
future.cancel(true);
bufferedInputStream.close();
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, blobDirectory)) {
if (blobItem instanceof BlobFile && blobItem.getPath().equals(path)) {
StorageClientSDKManager.getManager().deleteBlobFile(connectionString, (BlobFile) blobItem);
}
}
}
}
try {
directoryQueue.clear();
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
for (String pathDir : path.split("/")) {
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.getLast())) {
if (blobItem instanceof BlobDirectory && blobItem.getName().equals(pathDir)) {
directoryQueue.addLast((BlobDirectory) blobItem);
}
}
}
} catch (AzureCmdException e) {
String msg = "An error occurred while attempting to show new blob." + "\n" + String.format(message("webappExpMsg"), e.getMessage());
PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, e);
}
AzureTaskManager.getInstance().runLater(() -> fillGrid());
} catch (Exception e) {
Throwable connectionFault = e.getCause();
Throwable realFault = null;
if (connectionFault != null) {
realFault = connectionFault.getCause();
}
progressIndicator.setText("Error uploading Blob");
String message = realFault == null ? null : realFault.getMessage();
if (connectionFault != null && message == null) {
message = "Error type " + connectionFault.getClass().getName();
}
progressIndicator.setText2((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : message);
}
} catch (IOException e) {
PluginUtil.displayErrorDialogAndLog(message("errTtl"), "An error occurred while attempting to upload Blob.", e);
}
}));
}