@ApiMethod(name = "getBlobURL", scopes = {Constants.EMAIL_SCOPE}, clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID, com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID}, audiences = {Constants.ANDROID_AUDIENCE}) public BlobAttributes getBlobURL(User user) throws UnauthorizedException, ConflictException{ //If if is not null, then check if it exists. If yes, throw an Exception //that it is already present if (user == null){ throw new UnauthorizedException("User is Not Valid"); } BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); String blobUploadUrl = blobstoreService.createUploadUrl("/blobupload"); //BlobAttributes is a class BlobAttributes ba= new BlobAttributes(); ba.setBlobURL(blobUploadUrl); return ba; }
/** * Initializes a new instance of the BlobAttributes class. * * @param type * The type of blob to set. */ public BlobAttributes(final BlobType type) { this.setMetadata(new HashMap<String, String>()); this.setProperties(new BlobProperties(type)); }
final BlobAttributes attributes = new BlobAttributes(BlobType.parse(blobType)); final BlobProperties properties = attributes.getProperties(); attributes.setStorageUri(resourceURI); attributes.setSnapshotID(snapshotID); attributes.setMetadata(BaseResponse.getMetadata(request)); properties.setCopyState(getCopyState(request)); attributes.setProperties(properties); return attributes;
@Override public Void preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } // Set attributes final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(this.getConnection(), blob.getStorageUri(), blob.snapshotID); if (retrievedAttributes.getProperties().getBlobType() != blob.properties.getBlobType()) { throw new StorageException(StorageErrorCodeStrings.INCORRECT_BLOB_TYPE, String.format( SR.INVALID_BLOB_TYPE, blob.properties.getBlobType(), retrievedAttributes.getProperties() .getBlobType()), Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata(); return null; } };
final BlobAttributes attributes = new BlobAttributes(BlobType.parse(blobType)); final BlobProperties properties = attributes.getProperties(); attributes.setStorageUri(resourceURI); attributes.setSnapshotID(snapshotID); attributes.setMetadata(BaseResponse.getMetadata(request)); properties.setCopyState(getCopyState(request)); attributes.setProperties(properties); return attributes;
@Override public Void preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } // Set attributes final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(this.getConnection(), blob.getStorageUri(), blob.snapshotID); if (retrievedAttributes.getProperties().getBlobType() != blob.properties.getBlobType()) { throw new StorageException(StorageErrorCodeStrings.INCORRECT_BLOB_TYPE, String.format( SR.INVALID_BLOB_TYPE, blob.properties.getBlobType(), retrievedAttributes.getProperties() .getBlobType()), Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata(); return null; } };
@Override public Boolean preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_OK) { final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(this.getConnection(), blob.getStorageUri(), blob.snapshotID); blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata(); return Boolean.valueOf(true); } else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { return Boolean.valueOf(false); } else { this.setNonExceptionedRetryableFailure(true); // return false instead of null to avoid SCA issues return false; } } };
/** * Initializes a new instance of the BlobAttributes class. * * @param type * The type of blob to set. */ public BlobAttributes(final BlobType type) { this.setMetadata(new HashMap<String, String>()); this.setProperties(new BlobProperties(type)); }
@Override public Boolean preProcessResponse(CloudBlob blob, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_OK) { final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(this.getConnection(), blob.getStorageUri(), blob.snapshotID); blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata(); return Boolean.valueOf(true); } else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_NOT_FOUND) { return Boolean.valueOf(false); } else { this.setNonExceptionedRetryableFailure(true); // return false instead of null to avoid SCA issues return false; } } };
@Override public CloudBlob preProcessResponse(CloudBlobContainer container, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } // Set attributes final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(this.getConnection(), blobUri, snapshotID); CloudBlob blob; switch (retrievedAttributes.getProperties().getBlobType()) { case APPEND_BLOB: blob = container.getAppendBlobReference(blobName, snapshotID); break; case BLOCK_BLOB: blob = container.getBlockBlobReference(blobName, snapshotID); break; case PAGE_BLOB: blob = container.getPageBlobReference(blobName, snapshotID); break; default: throw new StorageException(StorageErrorCodeStrings.INCORRECT_BLOB_TYPE, SR.INVALID_RESPONSE_RECEIVED, Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata(); return blob; } };
@Override public CloudBlob preProcessResponse(CloudBlobContainer container, CloudBlobClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) { this.setNonExceptionedRetryableFailure(true); return null; } // Set attributes final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(this.getConnection(), blobUri, snapshotID); CloudBlob blob; switch (retrievedAttributes.getProperties().getBlobType()) { case APPEND_BLOB: blob = container.getAppendBlobReference(blobName, snapshotID); break; case BLOCK_BLOB: blob = container.getBlockBlobReference(blobName, snapshotID); break; case PAGE_BLOB: blob = container.getPageBlobReference(blobName, snapshotID); break; default: throw new StorageException(StorageErrorCodeStrings.INCORRECT_BLOB_TYPE, SR.INVALID_RESPONSE_RECEIVED, Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata(); return blob; } };
blob.getStorageUri(), blob.snapshotID); blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata();
blob.getStorageUri(), blob.snapshotID); blob.properties = retrievedAttributes.getProperties(); blob.metadata = retrievedAttributes.getMetadata();