how to upload to specific folder inside Azure blob container with Mule? - azure-storage

In my Mule 4 application I Azure Storage connector to successfully upload a blob to my Azure container:
However this adds the file into the root directory of "my-container".
I want to add the file to my-container/examples - i.e. the examples folder inside my-container.
How can I do this within Mule 4?
Connector XML (edit):
<azure-storage:upload-blob doc:name="Upload Json" doc:id="63fa613e-b355-4b6f-9f81-4ddd8dd40998" config-ref="azure_storage_config">
<azure-storage:storblob container="my-container" fileStream="#[payload]" fileName="file.json"/>
</azure-storage:upload-blob>

There is actually only a single layer of containers. What you see as folders in Azure are only "virtual" folders which are created by actually naming the objects in hierarchical manner.
In other words, all the objects are stored inside the container directly and when you create a file in a folder, what you are actually doing is creating the file with the name folder/filename
So, you can create the "virtual" folder by passing the filename like examples/file.json in the connector
<azure-storage:upload-blob doc:name="Upload Json" doc:id="63fa613e-b355-4b6f-9f81-4ddd8dd40998" config-ref="azure_storage_config">
<azure-storage:storblob container="my-container" fileStream="#[payload]" fileName="examples/file.json"/>
</azure-storage:upload-blob>

Related

Is it possible for Vue.js to add data to a file in AWS S3 bucket?

I am developing a simple application by Vue.js, which is trying to combine couples of strings as a array and name it as a new name. Now the problem is how can I save the combined data to some place so that I can access the combined data in the future. I am expecting I can save the data into AWS S3, however local is acceptable(such as public folder in the Vue.js code structure)
You can't save data into anything local from the client application (browser-run), unless it's installed as a standalone. What you need is to use AWS S3 JS SDK to upload directly into the bucket.

Create Blob storage UNC path in cloud

I have used blob storage as a file storage account in .NET Core Web application hosted on Azure app service(PaaS).
My requirement is to create .zip files and then attach to email where it requires UNC path for attachment.
Here I have one option to use app service local storage for temporary file creation and use in attachment.
I am searching other option to map blob storage to any virtual drive in cloud and get its UNC path or any other option?
Also, Can you please suggest what are the possible options to map Azure Blob storage drive in network? I know the following one - App service local storage, VM, Local machine network drive.
First of all, you need to know the concept of UNC path, and then azure webapp can be regarded as a virtual machine in essence, and azure blob storage can also be regarded as a machine. Therefore, it is not feasible to send mail directly through azure blob.
Suggestion:
1. I check the information, you can try azure files to store files and use them.
I think this should be the fastest way, without using other azure products.
Download the file to the project directory, you can create a temporary folder, such as: MailTempFolder, you can download the file from the blob to this folder, and then you can get the UNC path to send mail.
After the sending is successful, just delete the file, it will not occupy too much space of the azure webapp, even if the sending fails, you can still get the zip file without downloading it again.

How to create directories in AWS S3 using Apache NiFi putS3Object

I have a working config to push files from a directory on my server to an S3 bucket. NiFi is running on a different server so I have a getSFTP. The source files have subfolders my putS3Object current config does not support and jams all of the files at the root level of the S3 bucket. I know there's a way to get putS3Object to create directories using defined folders. The ObjectKey by default is set to ${filename}. If set to say, my/directory/${filename}, it creates two folders, my and the subfolder directory, and puts the files inside. However, I do NOT know what to set for the object key to replicate the file(s) source directories.
Try ${path}/${filename} based on this in the documentation:
Keeping with the example of a file that is picked up from a local file system, the FlowFile would have an attribute called filename that reflected the name of the file on the file system. Additionally, the FlowFile will have a path attribute that reflects the directory on the file system that this file lived in.

Nifi ListS3 processor not returning full path for files stored in S3

I am using the ListS3 processor to get files from S3 and piping it into the RouteOnAttribute processor. From there I am using the Route to Property name as the Routing Strategy and assigning properties bases on which files I am listening.
I am able to see all the files I want but can't do anything with them because my another processor down the line needs the full path of those files. I am using a python script, that takes in file path as cmd line arguments.
How do I extract the full absolute path of the files from S3?
You can list, download, and save S3 files locally using a sequence of NiFi processors like the following:
ListS3 - to get references to S3 objects you can filter. Output from ListS3 contains only references to objects, not the content itself, in attributes:
s3.bucket - name of the bucket, like my-bucket
filename - key of the object, like path/to/file.txt
FetchS3Object - to download object content from S3 using the bucket and key from ListS3 above.
PutFile - to store the file locally. Specify the Directory property where you want the files to be placed /path/to/directory. The filename attributes from S3 will contain relative paths from S3 keys, so these would be added to the Directory by default.
You can then assemble local paths for your Python script using NiFi expression language:
/path/to/directory/${filename}

Using data present in S3 inside EMR mappers

I need to access some data during the map stage. It is a static file, from which I need to read some data.
I have uploaded the data file to S3.
How can I access that data while running my job in EMR?
If I just specify the file path as:
s3n://<bucket-name>/path
in the code, will that work ?
Thanks
S3n:// url is for Hadoop to read the s3 files. If you want to read the s3 file in your map program, either you need to use a library that handles s3:// URL format - such as jets3t - https://jets3t.s3.amazonaws.com/toolkit/toolkit.html - or access S3 objects via HTTP.
A quick search for an example program brought up this link.
https://gist.github.com/lucastex/917988
You can also access the S3 object through HTTP or HTTPS. This may need making the object public or configuring additional security. Then you can access it using the HTTP url package supported natively by java.
Another good option is to use s3dist copy as a bootstrap step to copy the S3 file to HDFS before your Map step starts. http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/UsingEMR_s3distcp.html
What I ended up doing:
1) Wrote a small script that copies my file from s3 to the cluster
hadoop fs -copyToLocal s3n://$SOURCE_S3_BUCKET/path/file.txt $DESTINATION_DIR_ON_HOST
2) Created bootstrap step for my EMR Job, that runs the script in 1).
This approach doesn't require to make the S3 data public.