Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Apr 09, 2018 10:18

By Avner Gershtansky

How to use a VBS function to upload files, from local machine to MCM repository.

In order to use locally stored images, tables, or any other file with the Perfecto Mobile system, first the files need to be uploaded to the MCM repository. 
The article below explains the steps to do so, by using the function which is included as well.

upload_file_to_repository.vbs


Function upload_repository_item(url, file_to_upload, user_id, password, rep_type, rep_path)
    mcm_url = url
    src_file = file_to_upload
    strUserID = user_id
    strPassword = password
    repository_type = rep_type
    repository_path = rep_path
    strURL = mcm_url & repository_type & "/" & repository_path & _
             "?operation=upload&user=" & strUserID & "&password=" & strPassword
    Set HTTP = CreateObject ("Microsoft.XMLHTTP")
    Set objStream = CreateObject("ADODB.Stream")
    objStream.Type = 1
    objStream.Open 
    objStream.LoadFromFile src_file
    HTTP.open "PUT", strURL, False
    file_stream = objStream.Read
    HTTP.send file_stream
    Set HTTP = Nothing
End Function
' replace strings as needed
upload_repository_item "https://mycloud.perfectomobile.com/services/repositories/", _
                       "C:\Pictures\img2.png", "user@email.com", "password", _
                       "media", "public:folder_name/img.png"

In order to make the upload more secure, instead of using user_id and password, it is strongly recommended to use the securityToken instead.

To create the token, refer to How to create the security Token.

The upload_repository_item function will change as per below:

Function upload_repository_item(url, file_to_upload, security_token, rep_type, rep_path)
    mcm_url = url
    src_file = file_to_upload
    strSecurityToken = security_token
    repository_type = rep_type
    repository_path = rep_path
    strURL = mcm_url & repository_type & "/" & repository_path & _
             "?operation=upload&securityToken=" & strSecurityToken
    Set HTTP = CreateObject ("Microsoft.XMLHTTP")
    Set objStream = CreateObject("ADODB.Stream")
    objStream.Type = 1
    objStream.Open 
    objStream.LoadFromFile src_file
    HTTP.open "PUT", strURL, False
    file_stream = objStream.Read
    HTTP.send file_stream
    Set HTTP = Nothing
End Function
' replace strings as needed
upload_repository_item "https://mycloud.perfectomobile.com/services/repositories/", _
                       "C:\Pictures\img2.png", "myLongAndSecureSecurityToken", _
                       "media", "public:folder_name/img.png"