Home > other >  How could I send a curl output straight to an Azure Storage?
How could I send a curl output straight to an Azure Storage?

Time:01-27

I'm trying to send downloaded files using bash using a curl request:

    
for secao in $tipo_dou;
do
    download="curl -k --silent -fL -b cookies.iakim 'https://inlabs.in.gov.br/index.php?p=$ano-$mes-$dia&dl=$ano-$mes-$dia-$secao.zip' -H 'origem: 736372697074' -o


    " 
    echo $download > $ano-$mes-$dia-$secao.sh
    sh $ano-$mes-$dia-$secao.sh
    rm -rf $ano-$mes-$dia-$secao.sh
done

By doing that I was able to retrieve the data into my local machine.

The problem is: I must retrieve that data and send it towards an Azure Storage and for that I've been trying to make a pipe such this ex:

  filename=$ano-$mes-$dia&dl=$ano-$mes-$dia-$secao.zip
for secao in $tipo_dou;
do
    download="curl -k --silent -fL -b cookies.iakim 'https://inlabs.in.gov.br/index.php?p=$ano-$mes-$dia&dl=$ano-$mes-$dia-$secao.zip' -H 'origem: 736372697074' 
                 |
                curl -X PUT -T - -H x-ms-blob-type:BlockBlob 'https://server.blob.core.windows.net/ape/filename?st=2023-01-25T18:41:00Z&se=2025-12-01T02:41:00Z&spr=https&sv=2021-06-08&sr=c&sig=SIGNATUREID'


    " 
    echo $download > $ano-$mes-$dia-$secao.sh
    sh $ano-$mes-$dia-$secao.sh
    rm -rf $ano-$mes-$dia-$secao.sh
done

And so far I was only able to login into the system that I'm trying to download it but I got an error like this:

<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:6b17fae3-601e-0065-5483-31ec49000000
Time:2023-01-26T12:43:31.1912380Z</Message>

And to execute that script I'm using Node:

 const { exec } = require('child_process');
 const fs = require('fs');
 const zlib = require('zlib');
 
 const directoryFiles = fs.readdirSync('.');


 const download = exec('sh xml-downloader.sh', (error, stdout, stderr ) => {
     console.log('stdout: ', stdout);
        console.log('stderr: ', stderr);
        if (error !== null) {
            console.log('exec error: ', error);
        }
 })

Is there any other way that I could do that?

Appreciate any help!

CodePudding user response:

@FabioFaria as mentioned, you'll need to configure a SAS token to enable your app to access blob storage.

Alternatively, since you're already using node to run the application, you could create an app registration for your node application and use the blob client directly.

CodePudding user response:

I appreciate all the help I got so far here.

However I took a different path to fix this problem, and now I'm using a NodeJS function that I created and now I'm sending those files straight to the API.

Thanks a lot for all help.

  • Related