in PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.azureexplorer/src/com/microsoft/azuretools/azureexplorer/editors/BlobExplorerFileEditor.java [671:774]
private void uploadFile(final String path, final File selectedFile) {
Job job = new Job("Uploading blob...") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Uploading blob...", IProgressMonitor.UNKNOWN);
try {
final BlobDirectory blobDirectory = directoryQueue.peekLast();
final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(selectedFile));
monitor.subTask("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();
monitor.worked((int) (100 * progress));
monitor.subTask(String.format("%s%% uploaded", (int) (progress * 100)));
return null;
}
};
try {
StorageClientSDKManager.getManager().uploadBlobFileContent(
connectionString,
blobContainer,
path,
bufferedInputStream,
callable,
1024 * 1024,
selectedFile.length());
} catch (AzureCmdException e) {
e.printStackTrace();
} finally {
try {
bufferedInputStream.close();
} catch (IOException ignored) {
}
}
// while (!future.isDone()) {
// Thread.sleep(500);
// progressIndicator.checkCanceled();
if (monitor.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) {
DefaultLoader.getUIHelper().showException("Error showing new blob", e, "Error showing new blob", false, true);
}
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
fillGrid();
}
});
} catch (Exception e) {
Throwable connectionFault = e.getCause();
Throwable realFault = null;
if (connectionFault != null) {
realFault = connectionFault.getCause();
}
monitor.setTaskName("Error uploading Blob");
String message = realFault == null ? null : realFault.getMessage();
if (connectionFault != null && message == null) {
message = "Error type " + connectionFault.getClass().getName();
}
monitor.subTask((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : message);
}
} catch (Exception e) {
DefaultLoader.getUIHelper().showException("Error uploading Blob", e, "Error uploading Blob", false, true);
return Status.CANCEL_STATUS;
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}