3

Has anyone had success uploading an attachment larger than 10 MBs to an ArcGIS Online hosted feature service?

I know that this is not possible via a web browser. I'm trying to upload a video (.mp4) around 50 MBs. I broke the video into smaller chunks so that each .mp4 is less than 10 MBs. I tried the following python script using the uploadPart and addAttachment REST functions to achieve this. The parts upload successfully, and I then commit and add the attachment to the feature using the commit and addAttachment functions. However, the attachment is not an .mp4. It's an application/octet-stream of only 41 bytes.

Here is the python script I'm running:

import requests, json, os

# Disable warnings
requests.packages.urllib3.disable_warnings()

# Variables
username = "agol"
password = "*****"
id = 1252
TempDir = r"D:\Projects\Treddyfrin\Temp"

# Generate AGOL Token
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com', 'expiration': 21600}
r = requests.post(tokenURL, data = params, verify=False)
response = json.loads(r.content)
token = response['token']

# Register Item
print("Registering Item")
uploadURL = 'https://services2.arcgis.com/o9a0D2ZwwG8CDFVQ/arcgis/rest/services/Sewers/FeatureServer/uploads/register'
params = {'f': 'pjson', 'token': token, 'itemName': 'attachment1252', 'description': 'Attachment for feature 1252'}
r = requests.post(uploadURL, data = params, verify=False)
response = json.loads(r.content)
itemID = str(response['item']['itemID'])

# Upload Parts of video to Registered Item
def addPart(itemID, token, filename, num):
    '''Add part of the input video using a post request through the request module'''

    print("Adding parts of video")

    addpartURL = 'https://services2.arcgis.com/o9a0D2ZwwG8CDFVQ/arcgis/rest/services/Sewers/FeatureServer/uploads/' + itemID + '/uploadPart'
    params = {'token':token, 'f':'pjson', 'partNumber': str(num)}
    image = {'partFile': (os.path.basename(filename), filename, 'video/mp4')}
    response = requests.post(addpartURL, data = params, files = image)
    print(json.loads(response.text))

# Walk through temp directory to get each video part
for a, b, c in os.walk(TempDir):
    for name in c:
        print(name)
        index = int(name.replace('output', '').replace('.mp4', ''))
        addPart(itemID, token, os.path.join(TempDir,name), index)

# Commit upload
print("Commiting upload")
commitURL = 'https://services2.arcgis.com/o9a0D2ZwwG8CDFVQ/arcgis/rest/services/Sewers/FeatureServer/uploads/' + itemID + '/commit'
params = {'f': 'pjson', 'token': token}
response = requests.post(commitURL, data = params)
print(json.loads(response.text))

# Add attachment to feature
print("Adding attachment to feature")
fsURL = 'https://services2.arcgis.com/o9a0D2ZwwG8CDFVQ/ArcGIS/rest/services/Sewers/FeatureServer/0/' + str(id) + '/addAttachment'
params = {'f': 'pjson', 'token': token, 'uploadId': itemID}
response = requests.post(fsURL, data = params)
print(response.content)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.