0

I've got app function which uploads some rar. file straight from browser to my blob storage. This file is ~60mb. My functions uploads like 6-7kb of this file and stops (no error appears).

The goal is to upload file straight from browser because my internet connection is low and I prefer computing resources to do the job (Is my understanding good? Compute resources will do the job if uploading from browser?).

Anyway here is my code:

def download_file(link):
    file = requests.get(link, stream=True)
    return file.content

def get_blobclient(container=None, file_name=None):
    blob_service_client = BlobServiceClient.from_connection_string(CONN)
    blob_client = blob_service_client.get_blob_client(container, file_name)
    return blob_client

def main(req):
    logging.info('Python HTTP trigger function processed a request.')
    error_message = None
    params = {key:req.params.get(key) for key in ("container", "file")}
    try:
        if not None in params.values():
            link = f'https://www21.zippyshare.com/d/{params.get("link")}'
            blobClient = get_blobclient(container=params.get("container"), file_name=params.get("file"))
            logging.info("Uploading file...")
            blobClient.upload_blob(download_file(link), blob_type="BlockBlob")
            logging.info("File has been uploaded")
            return func.HttpResponse(
                    "File has been uploaded",
                    status_code=200
            )
        else:
            error_message = f'{" ".join(str(k) for k,v in params.items() if v == None)}: These values have not been provided'
            logging.info(error_message)
    except Exception as error:
        logging.info(error)
    return func.HttpResponse(
        "Something went wrong..." if error_message is None else error_message,
        status_code=401
    )
rarova
  • 23
  • 3
  • 1
    It would be best if instead of uploading the data, you use blobfuse to mount your drive to a storage account. In this case, you will write your file locally (local to your script) but the data will be available on the storage account. https://learn.microsoft.com/en-us/azure/storage/blobs/storage-how-to-mount-container-linux – alif Aug 23 '21 at 20:54
  • Adding a second recommendation for blobfuse. I've had great results, with FUSE generally. – dwellman Aug 23 '21 at 21:05

1 Answers1

0

You can try the solution mentioned HERE where they upload a large file in chunks.

Anupam Chand
  • 2,209
  • 1
  • 5
  • 14