Creating folders with the uploaded files using flask to blob - file-upload

I want to create folders using flask to store in azure blob . I need help to write the code in flask to store all the files of a registration page to a folder and that folder to be uploaded in azure blob storage.
I want to create folders for every user at register time. So how can I create a simple empty folder at particular path in flask.
i tried uploading the files from the web page to the azure blob storage and all files are getting uploaded.
but i want a separate folder to every single user who registers and this folders to be uploaded in the blob storage
This is the code of app.py to upload the files to blob storage:
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in allowed_ext
#app.route('/upload',methods=['POST'])
def upload():
if request.method == 'POST':
files = request.files.getlist('file')
for file in files:
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(filename)
blob_client = blob_service_client.get_blob_client(container = container, blob = filename)
with open(filename, "rb") as data:
try:
blob_client.upload_blob(data, overwrite=True)
msg = "Upload Done ! "
except:
pass
os.remove(filename)
return render_template("dashboard.html", msg=msg)
This is the html code of the files to be uploaded:
<form action="/upload" method="POST" enctype="multipart/form-data">
<div><label>Bank Statement*</label><input type="file" name="file" ></div>
<div><label>Affidant of support in case of someone sponsoring the education*</label><input type="file" name="file" ></div>
<div><label>Test of English Fulency- Duolingo/GRE/IELTS/TOEFL/OTHERS*</label><input type="file" name="file"></div>
<div><label>2022-23 River Certificate of finances for international students*</label><input type="file" name="file" ></div>
<hr>
<div class="button">
<input type="submit" name="upload" value="Upload" class="btn btn-success">
</div>
{{msg}}
</form>

Related

How to save and edit images by ckeditor in Laravel 8

I am saving some images which created & upload by CKEditor in my Laravel application and it getting saved properly. But when I want to edit the content, sometimes I am getting the content from DB and load it into CKEditor.
But Most of the cases, the page loading & loading ..... And The content not loads. Sometimes loads properly, but see the string as the attached image below.
How to solve this error!!
<textarea name="long_desc" class="form-control" id="summernote" rows="20">{{ $portfolio_data->long_desc}}</textarea>
<textarea name="long_desc" class="form-control" id="summernote" rows="20">{{ $portfolio_data->long_desc}}</textarea>
you can use {!! !!} for loading page content in blade engine in laravel instead of {{ }}
write like this:
<textarea name="long_desc" class="form-control" id="summernote" rows="20">{!! $portfolio_data->long_desc !!}</textarea>

Testcafe - Unable to upload files with input type="url" which is a react custom made file upload component

I am trying to upload a file but getting error "The specified selector does not match a file input element", I know testcafe requires input type="file" for uploading files, But as we are reusing our custom component for file uploads where we are giving input type="url" It's not working with testcafe.
Here is the java script/HTML code
<input name="images" accept="image/*" type="url" class="form-control col-11 false" value="">
And I am trying to access the css selector like this
const click_add_image=Selector('input[name="images"]')
const add_image=Selector('input[name="images"],input[inputtype="url"]')
test
('add images', async t=>{
await t
.click(click_add_image)
.wait(2000)
.setFilesToUpload(add_image,[
'./_uploads_/Share_Knowledge.png'
])
I am getting error The specified selector does not match a file input element

Laravel 5.3 - image upload not working

I have an input field for image upload in my view:
<input type="file" class="form-control" name="image">
I have created folder uploads in my public folder and in my Controller I am trying to upload a file like this:
$path = $request->file('image')->store('uploads/', 'public');
When I submit the form and upload an image nothing gets uploaded to the folder uploads and I get the error:
SQLSTATE[HY000]: General error: 1364 Field 'image' doesn't have a
default value
Have you try to put enctype and files on your form ->
enctype="multipart/form-data" files="true"

MVC4 VB.NET Multiple File Upload

I want to upload multiple files into my website onclick of submit.
I was able to achieve this partially. Multiple files are being uploaded in my website. But the problem is that i want different file uploads to upload files in different location using the same Controller
For eg
<form name="upload" id="upload" action="~/Home/MultiUpload" method="post" enctype="multipart/form-data">
<label>Filename: <input type="file" name="file1" /></label>
<label>Filename: <input type="file" name="file2" /></label>
<label>Filename: <input type="file" name="file3" /></label>
<input type="submit" value="Submit" />
</form>
From the above code, I want file1 to upload file to ~/App_Data/Uploads1, file2 to ~/App_Data/Uploads2 and file3 to ~/App_Data/Uploads3
Here is my code of the controller trying to save the files
Function MultiUpload(file As List(Of HttpPostedFileBase)) As ActionResult
If (Not IsNothing(file)) Then
For Each item As HttpPostedFileBase In file
Dim filePath = IO.Path.Combine(Server.MapPath("~/App_Data/Uploads"), IO.Path.GetFileName(item.FileName))
item.SaveAs(filePath)
Next
End If
Return RedirectToAction("Index")
End Function
As mentioned earlier, all the files are uploading files to the same location.
If uploading to different locations is somehow not possible, i would atleast want to track which filename is coming from which FileUpload
Thanks for your help
Very much appreciated

I am unable to upload file to my local host folder in php

I have the follwing code
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
my page is in http://local.host/nausal/upload.php
now I am having the follwing error though i have created a folder in site with name upload.
Notice: Undefined index: uploaded in C:\wamp\www\Nausal\upload.php on line 15
Notice: Undefined index: uploaded in C:\wamp\www\Nausal\upload.php on line 17
Sorry, there was a problem uploading your file.
If the form is a part of upload.php too, you need to encapsulate the PHP-code and first check if $_FILES is not empty, otherwise you will always get a Notice if you only want to display the form.
<?php
if(!empty($_FILES))
{
//your PHP-code here
}
?>
<!-- your form here -->
Khan sb Place this code in file
called upload.php
create a folder called upload where
you created upload.php
change echo "The file ". basename(
$_FILES['uploadedfile']['name']). "
has been uploaded"; to echo "The
file ". basename(
$_FILES['uploaded']['name']). " has
been uploaded";
This will upload file successfully. First time when upload.php is uploaded there is no file selected so you will see some errors. But after you select a file and click upload you will not see any error. To avoid this error do as suggested by Dr. Molle