Uploading Files Not Working - Need Assistance

Uploading Files Not Working - Need Assistance

IMO, what you're trying to do is indeed a legit scenario for UI testing automation. IIRC, in early versions of IE it was possible to populate the <input type="file"/> field with a file name, without showing up the Choose File dialog. For security reason, this is no longer possible, so you have to send keys to the dialog.

The problem here is that file.InvokeMember("Click") shows a modal dialog, and you want the keys to be sent to that dialog, but SendKeys.Send gets executed after the dialog has been closed (it's modal, after-all). You need to let the dialog open first, then send the keys and let it close.

This problem can be solved using WinForms Timer, but I'd prefer using async/await and Task.Delay for this (working code):

async Task PopulateInputFile(HtmlElement file)
{
file.Focus();

// delay the execution of SendKey to let the Choose File dialog show up
var sendKeyTask = Task.Delay(500).ContinueWith((_) =>
{
// this gets executed when the dialog is visible
SendKeys.Send("C:\\Images\\CCPhotoID.jpg" + "{ENTER}");
}, TaskScheduler.FromCurrentSynchronizationContext());

file.InvokeMember("Click"); // this shows up the dialog

await sendKeyTask;

// delay continuation to let the Choose File dialog hide
await Task.Delay(500);
}

async Task Populate()
{
var elements = webBrowser.Document.GetElementsByTagName("input");
foreach (HtmlElement file in elements)
{
if (file.GetAttribute("name") == "file")
{
file.Focus();
await PopulateInputFile(file);
}
}
}

IMO, this approach is very convenient for UI automation scripts. You can call Populate like this, for example:

void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
this.webBrowser.DocumentCompleted -= webBrowser_DocumentCompleted;
Populate().ContinueWith((_) =>
{
MessageBox.Show("Form populated!");
}, TaskScheduler.FromCurrentSynchronizationContext());
}

Uploading Files Not Working - trim the initial characters

You are right @soohoonigan the sendkeys comes up too fast but that is not an answer for that. I did this like that.

Here is my code:

Dim el = elc.GetElementsByName("UploadedFile")
SetFile()
el.Item("UploadedFile").InvokeMember("Click")

Public Async Sub SetFile()

Await Task.Delay(1000)
SendKeys.Send("c:\Capture.png" & "{ENTER}")

End Sub

It's working fine.

File upload is not working in server but working locally

It is probably a permission issue on the destination folder.

Do sudo chmod -R 777 /destination/folder and try again. Then it should work. If you still can't upload your file, maybe the permission problem is on a parent directory.

After that, find which user (and its group) is the owner of your uploaded file.

Then set the permission back, and change the owner of your directory : sudo chown -R owner_user.group /destination/folder.

File upload not working for all files

For that file "Holidays.docx'" it seems to me that file exceeds upload_max_filesize. At least that is what the var_dump said about $_FILES['file']['error'] which is equal to 1 (UPLOAD_ERR_INI_SIZE)

You should chech php.ini settings upload_max_filesize and post_max_size because that is the actual limit of how large file can be uploaded to server. By default upload_max_filesize = 2M so your 5MB limit means nothing.

Also you can use ini_get('upload_max_filesize'); to get runtime setting.

If you are unsure where is your php.ini configuration file located use phpinfo().

Also to know about is that PHP will return $_FILES['file']['size'] equal to 0 if file exceeds file size limit - which is exactly what happened.

So IMO everything is working as it should be. You should post more var_dump() infos for other files that don't upload.

Also to note, you don't check file extensions in case-insensitive manner so files with extensions like .DOCX will not be accepted by your script.

Google drive Python to upload file not working

A service account is not you. A service account is a dummy user, it has its own drive account. Files it uploads are owned by it.

Your file is probably being uploaded to the service accounts drive account. or where ever '15xc7s-dFnpW6pjtjtUH4kT1BnZ46ffFh' is assuming that the service account has access to write to that directory. You can see this by doing a file.list and seeing which files it currently has access to.

If the file to create was successful it will return a file.id as part of the response you can check that as well.

You could create a directory on your own google drive account share that directory with the service account. Then have the service account upload files into that directory then you would be able to see them on your own account. You would also need to grant yourself permissions to the file when its uploaded. Look into permissions.create.

Alternatively you could have the service account upload the files to its own account and then add permissions for you to the file so that you would be able to see it. Look into permissions.create.

File upload stopped working

According to this, it appears that @filename has been deprecated in PHP >= 5.5.0:
Can anyone give me an example for PHP's CURLFile class?

Problems with file upload when going from localhost to web host

A possible problem is that you don't have permissions to write into the target directory!!

Please check if you are able to with your provider. You may have to set FTP permissions 777 to upload directory or to choose a different upload path that is given by your ISP.

At least that is the most typical issue.

And please, next time format your questions better.



Related Topics



Leave a reply



Submit