📅  最后修改于: 2022-03-11 15:00:44.809000             🧑  作者: Mango
// Create a source file client
ShareFileClient dirClient = new ShareFileClientBuilder()
.endpoint("https://xxx.file.core.windows.net")
.shareName("xxx")
.credential(new StorageSharedKeyCredential("xxx", "xxx"))
.resourcePath("photos" + "/" + "test.png")
.buildFileClient();
var base64Image = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
// Create a source file
try {
var sizeInBytes = 4 * Math.ceil(base64Image.length() / 3)*0.5624896334383812;
dirClient.create((long) sizeInBytes);
} catch (ShareStorageException e) {
System.out.println("Failed to create source client. Reasons: " + e.getMessage());
}
// decodeBase64
byte[] bytes = Base64.decodeBase64(base64Image);
// Upload
try (ByteArrayInputStream dataStream = new ByteArrayInputStream(bytes)) {
dirClient.upload(dataStream, bytes.length);
} catch (IOException e) {
e.printStackTrace();
}