Le fait était que vous ne pouviez pas ajouter à moins que le BLobItem TYPE ait été créé en tant que BLOB APPEND.
package hello.azure.blobstorage;
import java.util.Date;
import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.BlobRequestOptions;
import com.microsoft.azure.storage.blob.CloudAppendBlob;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
public class WriteData2 {
// copy from azure console
public static final String storageConnectionString = "{yourString}";
public static void main(String[] args) {
CloudStorageAccount storageAccount;
CloudBlobClient blobClient = null;
CloudBlobContainer container = null;
String containerName = "{yourContainerName}";
String blobName = "{yourBlobName}";
try {
// Parse the connection string and create a blob client to interact with Blob
// storage
storageAccount = CloudStorageAccount.parse(storageConnectionString);
blobClient = storageAccount.createCloudBlobClient();
container = blobClient.getContainerReference(containerName);
{
CloudAppendBlob cab = container.getAppendBlobReference(blobName);
if (cab.exists() == false) {
// BLOB TYPE :Créé en tant qu'append Blob
cab.createOrReplace();
}
BlobRequestOptions options = new BlobRequestOptions();
options.setAbsorbConditionalErrorsOnRetry(true);
//Erreur si TYPE BLOB n'est pas Ajouter un objet blob
// Error returned from the service. Http code: 306 and error code:
// IncorrectBlobType
cab.appendText("Hello " + new Date() + "\n", "UTF-8", null, options, null);
}
System.err.println("finished.");
} catch (StorageException ex) {
ex.printStackTrace();
System.err.println(
String.format("HttpStatusCode=%d,ErrorCode=%d", ex.getHttpStatusCode(), ex.getErrorCode()));
} catch (Exception ex) {
ex.printStackTrace();
} finally {
}
}
}
Recommended Posts