azure-docs
azure-docs copied to clipboard
Java BlobOutput path substitution based on HttpTrigger body
Is there a way to modify the "path" for the @BlobOutput annotation inside the code? Use Case: Receiving an XML through an HttpTrigger. Reading stuff out of the received XML would determine how the path inside the BlobOutput should look like, e.g. some base "myblob/" is defined and on top of it we read out of the xml the "senderId" and a "filename". As we do some checks on the XML, we determine that the received body is more "trustworthy" than possible sent headers (and/or the sending party can't be modified to send the needed headers).
Code example:
@Suppress("TooGenericExceptionCaught")
@FunctionName("myRequest")
@StorageAccount("AzureWebJobsBlobSpace")
fun execute(
@HttpTrigger(
name = "request",
methods = [HttpMethod.POST],
authLevel = AuthorizationLevel.ANONYMOUS
) request: HttpRequestMessage<String>, context: ExecutionContext,
@BlobOutput(
name = "target",
path = "myblob/"
) outputItem: OutputBinding<String>
): HttpResponseMessage {
logger.info { "BEGIN request for participant_number '${request.headers["participant_number"] ?: "none"}'" }
return try {
val handleRequest = super.handleRequest(request.body, context)
// use response from handleRequest to determine the blob path
outputItem.value = request.body
request
.createResponseBuilder(HttpStatus.ACCEPTED)
.body("done")
.build()
} catch (e: Exception) {
handleError(e, request, context)
}
}
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 910d4732-bb08-d16a-a932-19c6bd1628c2
- Version Independent ID: af4358c7-cb5c-bdc7-6433-289f47dc186b
- Content: Azure Blob storage output binding for Azure Functions
- Content Source: articles/azure-functions/functions-bindings-storage-blob-output.md
- Service: azure-functions
- GitHub Login: @ggailey777
- Microsoft Alias: glenga
@Lesrac Thanks for your feedback! We will investigate and update as appropriate.
@Lesrac , The "path" for the @BlobOutput cannot be changed at runtime as it is a part of the Function definition. You will have to use the blob storage java SDK to write to the blob once you figure out the path
@Lesrac , Hope my answer helps! I will close this issue for now. Feel free to reopen if required