# Uploading a file using File object

**URL:** <https://forum.robotframework.org/t/uploading-a-file-using-file-object/7940>\
**Category:** Browser\
**Created:** [16 October 2024 01:34 UTC](https://forum.robotframework.org/t/uploading-a-file-using-file-object/7940 "2024-10-16T01:34:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yadubhushan](https://avatars.discourse-cdn.com/v4/letter/y/7ea924/32.png) [@yadubhushan](https://forum.robotframework.org/u/yadubhushan)\
**Post date:** [16 October 2024 01:34 UTC](https://forum.robotframework.org/t/uploading-a-file-using-file-object/7940/1 "2024-10-16T01:34:27Z")

</div>

We have a requirement to upload a file using browser library’s keyword ‘Promise to Upload file’. However, We do not have a physical file to provide the path, Instead we have a file object with us. How do we achieve upload in this case? Could someone assist on this?

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [16 October 2024 05:01 UTC](https://forum.robotframework.org/t/uploading-a-file-using-file-object/7940/3 "2024-10-16T05:01:23Z")

</div>

Hi,

If your file object/content can be written, you could create a temporary file to upload, then manage to remove it at the end of file?  
Something like this:

```
import tempfile

def create_temp_file(content):
    with tempfile.NamedTemporaryFile(delete=False, mode='w') as temp_file:
        temp_file.write(content)
        return temp_file.name

```

Other than that and a physical file, I’m not sure you can pass a file-object.  
Hopefully someone has a solution.

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [16 October 2024 08:22 UTC](https://forum.robotframework.org/t/uploading-a-file-using-file-object/7940/4 "2024-10-16T08:22:58Z")

</div>

I’ll second what charlie said, but add that OperatingSystem library has [Create File](https://robotframework.org/robotframework/latest/libraries/OperatingSystem.html#Create%20File) and [Remove File](https://robotframework.org/robotframework/latest/libraries/OperatingSystem.html#Remove%20File) to help you do this, combine that with [Built-in variable’s](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#toc-entry-333) ${TEMPDIR} variable and you should have everything you need to create a temporary file and then remove it within your test.

Dave.
