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
Related
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>
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>
I have such an input file tag:
<input type="file"
#fileInput formControlName="browseDocument"
id="uploadFile"
(change)="uploadFileEvt($event)"
name="uploadFile"
accept=".pdf,.xml"
/>
I want to test the upload file, but I need that uploadFileEvt function will be executed.
How could I cause it to happen in the test?
Thanks!
I think you just need to use .trigger('change') after the .attachFile() or .selectFile(),
cy.get('input[type=file]')
.selectFile({...})
.trigger('change')
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"
I'm running a login form, which - in case of success - forwards the user to a specific page via JS location.href. The browsers correctly recognize the form as a login form and offer to save the password. Now only in Google Chrome, the prompt disappears once the location changes. So the prompt is visible for just a split second, making it impossible to save the password.Is there any solution for this? Refreshing after login success is a common thing, so there should be a way to fix this..
Edit:
This is what the form looks like:
<form id="loginform" action="process.php" target="processframe" method="POST">
<input id="login_name" name="name" type="text" placeholder="Username"><br>
<input id="login_password" name="password" type="password" placeholder="Password"><br>
<button>Submit</button>
</form>
<iframe src="" id="processframe" name="processframe" style="display:none;"></iframe>
So the request is processed in an iframe. process.php then calls a javascript function:
window.setTimeout("parent.loginsuccess()", 1000);
The loginsuccess() function:
function loginsuccess()
{
location.href="/home.php";
}