Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy

Upload files to devices in App Automate

Important: Ability to upload non-media files on devices is available only under Device Cloud Pro, Device Cloud Pro + Visual Cloud and Enterprise plans. For more details, please checkout 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 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 version

The following tab list the supported file types you can upload, and the OS version on which you can upload the files.

The following table shows the supported file types and their maximun 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 "username:accesskey" \
  -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']
}
Note:
  • 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 command

You can also upload files using Appium’s push and pull file command, which doesn’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 (media, data, text, etc.) to the device and the pull file command to retrieve the files from the device.

Note: Appium’s push and pull file functionality is supported only for Appium version 1.15.0and 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 iOS device.

Before uploading, ensure that:

  • Your iOS app has UIFileSharingEnabled key set to true in the Info.plist file to enable file sharing. Files are then made available in the iTunes app. Optionally, you can set the LSSupportsOpeningDocumentsInPlace key set to true in the Info.plist file to expose your app’s folder in the Files app.
  • The destination path to push a file is in the following format: @<app_bundle_id>:documents/<image_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 some 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

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