I'm trying to Upload some files form my PC through a azure function app. At first i read some excel files then i do some Cleaning processes using Pandas and i want to upload it to Azure function app. offline every works fine, but as i published to Azure it gives Error 500. I'm guessing it can't get files from my PC.
my code looks like this:
#I get my files offline
AISauftragID = req.params.get('ID','756382')
Position = req.params.get('Position','7')
location = fr'C:\Users\bb\ff\Doc\VS Code\{ID}-{Position}'
#Some Cleaning using pandas
#connecting to Azure
blob_service_client = BlobServiceClient.from_connection_string("blablabla")
# Instantiate a new ContainerClient
container_client = blob_service_client.get_container_client('foldername')
try:
# Create new Container in the service
container_client.create_container()
properties = container_client.get_container_properties()
except ResourceExistsError:
print("Container already exists.")
blob = BlobClient.from_connection_string(conn_str="blablabla",
container_name="foldername",
blob_name="filename")
if blob.exists():
logging.info('filename.csv exists')
return func.HttpResponse(
"filename.csv exists",
status_code=200)
else:
blob_client = container_client.get_blob_client("filename.csv")
# upload data
blob_client.upload_blob(dataframe.to_csv(index=False, encoding = "utf-8"), blob_type="BlockBlob")
return func.HttpResponse(
"Konto.csv exists",
status_code=200)
my function.Json file looks like this:
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
CodePudding user response:
I'm guessing it can't get files from my PC.
That is correct. The azure function runs somewhere in an Azure Cloud data center. There is no way this function can access the local harddrive of an on-premises workstation. Also, you really don't want to because it would be a major security risk.
You seem to have the idea to use an azure function for uploading the local file, as stated, that is a no go. You need some client process like a browser or application to send the file to azure and then you can write an azure function or whatever to process that file.
To process a file you either create an http triggered azure function that accepts a POST action with the file content or you upload the file to, for example, azure blob storage and create a blob triggered / event grid triggered azure function to process the file.