Skip to main content
🚀 Self Healing AI Agent now live in App Automate! Auto-fix flaky tests instantly with zero code changes. Enable now!
No Result Found
Connect and get help from 7,000+ developers on our Discord community. Ask the CommunityAsk the Community

Upload your files on App Automate

Upload your media and non-media files on App Automate for running your tests in Appium.

Uploading non-media files on devices is available only under the Device Cloud Pro, Device Cloud Pro + Visual Cloud, Enterprise Device Cloud Pro, and Enterprise Device Cloud Pro + Visual Cloud plans. For more information, see our pricing page.

App Automate provides preloaded media files on BrowserStack remote devices to test scenarios that require access to files from the device.

Apart from preloaded media files, you can also upload your media or non-media files in App Automate.

Use either of the following methods to upload your media or non-media files to BrowserStack remote devices:

  • Use BrowserStack’s REST API and capability to upload media files, such as images and videos, to the device gallery or camera roll, or to upload non-media files, such as documents and spreadsheets, before your test runs. The uploaded files stay available throughout the session.
  • Use Appium’s push and pull file commands to copy a file to a specific folder on the device, or to retrieve a file from the device, during the test itself. This method doesn’t require any BrowserStack API or capability.

BrowserStack’s REST API and capability

App Automate provides a REST API request and a capability to upload your files to BrowserStack’s remote devices and access them during testing.

In this section, you’ll learn:

Supported file types and OS versions

The following tabs list the supported file types you can upload and the OS versions on which you can upload files.

The following table shows the supported file types and their maximum file size allowed to upload:

File Type Maximum file size
Image JPG, JPEG, PNG, GIF, BMP 10 MB
Video MP4, MOV and 3GP 50 MB
Non-media XLS, XLSX, DOC, DOCX, PDF, CSV, TXT 15 MB

The following table shows the supported OS and devices to which you can upload your files for testing:

OS Device OS version
Android Phones and tablets v6 and above
iOS iPhones and iPads v13 and above (Non-media), v10 and above (Image, Video)

Upload your file to BrowserStack

Run the following upload media cURL command to upload your file to BrowserStack servers:

  curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
  -X POST "https://api-cloud.browserstack.com/app-automate/upload-media" \
  -F "file=@/path/to/your/file" \
  -F "custom_id=SampleFile"

A sample response for the given cURL command is as follows. It returns the value of the media_url parameter.

{
  "media_url": "media://90c7a8h8dc82308108734e9a46c24d8f01de12881",
  "custom_id": "SampleFile"
}

The file you uploaded will be available in the following folders on the device:

Android: Default gallery app.
The file path is /sdcard/Pictures for images and /sdcard/Movies for videos.

iOS: Camera Roll.
The file path to camera roll directory is /private/var/mobile/Media/DCIM/.

Android: Default Downloads folder of the device

iOS: App’s directory in the device. The file path is Files app → On My iPhone → Your app's directory → ‘Custom_Files’ folder created by BrowserStack.

Set the capability in test script

Set the browserstack.uploadMedia capability to the value of the media_url parameter returned in the API response as shown in the following code snippets:

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.uploadMedia", new String[]{"media://90c7a8h8dc82308108734e9a46c24d8f01de12881"});
var capabilities = {
	'browserstack.uploadMedia': ['media://90c7a8h8dc82308108734e9a46c24d8f01de12881']
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserstack.uploadMedia", new[] {"media://90c7a8h8dc82308108734e9a46c24d8f01de12881"});
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.uploadMedia", ["media://90c7a8h8dc82308108734e9a46c24d8f01de12881"]);
desired_cap = {
	'browserstack.uploadMedia': ['media://90c7a8h8dc82308108734e9a46c24d8f01de12881']
}
desired_caps = {
    'browserstack.uploadMedia': ['media://90c7a8h8dc82308108734e9a46c24d8f01de12881']
}
  • The number of file uploads allowed per session is 5.
  • Files are stored on BrowserStack servers for at most 30 days.
  • In the case of non-media files, ensure that your iOS app has the UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace keys set to true in the Info.plist file. This is required to make your app’s folder available in the Files app.

Appium’s push and pull file commands

You can upload files using Appium’s push and pull file commands, which don’t use any BrowserStack capability or API to upload your files to BrowserStack remote devices during testing.

During testing, use Appium’s push file command to copy your files, such as media, data, and text files, to the device. Use the pull file command to retrieve the files from the device.

Appium’s push and pull file functionality is supported only for Appium version 1.15.0 and above.

In your test script, write commands to copy files to and retrieve files from /sdcard/Download/, /sdcard/Pictures, and /sdcard/Android/data/<your_app_package> folders on the Android device.

The following code snippets show how to use the push and pull file commands:

// Push a file
driver.pushFile("/sdcard/Download/image.jpg", new File("/Users/johndoe/Desktop/image.jpg"));

// Pull file
byte[] fileBase64 = driver.pullFile("/sdcard/Download/image.jpg");
// Push file webdriver.io example
let data = Buffer.from("Hello World").toString('base64');
driver.pushFile('/sdcard/Download/file.txt', data);

// Push file wd example
await driver.pushFileToDevice('/sdcard/Download/file.txt', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');

// Pull file webdriver.io example
let data = driver.pullFile('/sdcard/Download/file.txt');

// Pull file wd example
let data = await driver.pullFile('/sdcard/Download/file.txt');
// Push a file
driver.PushFile("/sdcard/Download/image.jpg", new FileInfo("/Users/johndoe/Desktop/image.jpg"))

// Pull file
byte[] fileBase64 = driver.PullFile("/sdcard/Download/image.jpg");
// Push a file
$driver->pushFile('/sdcard/Download/file.txt', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');

// Pull file
$data = $driver->pullFile('/sdcard/Download/file.txt');
# Push a file
dest_path = '/sdcard/Download/file.txt'
driver.push_file(dest_path, 'Hello World'.encode("utf-8"))

# Pull file
file_base64 = driver.pull_file(dest_path)
# Push a file
driver.push_file('/sdcard/Download/image.jpg', File.read('/Users/johndoe/Desktop/image.jpg'))

# Pull file
pull_file('/sdcard/Download/image.jpg')

In your test script, write commands to copy files to and retrieve files from your app’s documents folder on the iOS device.

Before you push or pull files, ensure the following:

  • Your iOS app has the UIFileSharingEnabled key set to true in the Info.plist file. This key exposes your app’s documents folder, which is where the push and pull commands read from and write to. In Xcode, this key appears as Application supports iTunes file sharing. The iTunes name is historical, referring to how you accessed these files on a locally connected device. You don’t need iTunes, Finder, or any other app to push and pull files during your tests on BrowserStack.
  • To also make the documents folder available in the on-device Files app, set the LSSupportsOpeningDocumentsInPlace key to true in the Info.plist file. This step is optional.
  • The destination path to push a file uses the following format: @<app_bundle_id>:documents/<file_name>.png.

The following code snippets show how to use the push and pull file commands:

// Push an image file
driver.pushFile("@com.browserstack.Sample-iOS:documents/image.jpg", new File("/Users/johndoe/Desktop/image.jpg"));

// Pull file
byte[] fileBase64 = driver.pullFile("@com.browserstack.Sample-iOS:documents/image.jpg");
// Push file webdriver.io example
let data = Buffer.from("Hello World").toString('base64');
driver.pushFile('@com.browserstack.Sample-iOS:documents/file.txt', data);

// Push file wd example
await driver.pushFileToDevice('@com.browserstack.Sample-iOS:documents/file.txt', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');

// Pull file webdriver.io example
let data = driver.pullFile('@com.browserstack.Sample-iOS:documents/file.txt');

// Pull file wd example
let data = await driver.pullFile('@com.browserstack.Sample-iOS:documents/file.txt');
// Push an image file
driver.PushFile("@com.browserstack.Sample-iOS:documents/image.jpg", new FileInfo("/Users/johndoe/Desktop/image.jpg"))

// Pull file
byte[] fileBase64 = driver.PullFile("@com.browserstack.Sample-iOS:documents/image.jpg");
$driver->pushFile('@com.browserstack.Sample-iOS:documents/foo.bar', 'QXJlIHlvdXIgYmVlcnMgb2theT8=');

// Pull file
$data = $driver->pullFile('@com.browserstack.Sample-iOS:documents/foo.bar');
# Push an image file
driver.push_file('@com.browserstack.Sample-iOS:documents/image1.png', source_path='/Users/johndoe/Desktop/image1.png')

# Push a text file
dest_path = '@com.browserstack.Sample-iOS:documents/file.txt'
driver.push_file(dest_path, 'Hello World'.encode("utf-8"))

# Pull file
file_base64 = driver.pull_file(dest_path)
# Push an image file
driver.push_file('@com.browserstack.Sample-iOS:documents/image.jpg', File.read('/Users/johndoe/Desktop/image.jpg'))

# Pull file
pull_file('@com.browserstack.Sample-iOS:documents/image.jpg')

Need help?

If you need any help with this feature, get in touch with us.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Test web and mobile, from manual to automation, on real devices in one unified platform.

Contact Us

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle