Pearson
Always Learning

Whenever you need to upload files to a LearningStudio API, such as Doc Sharing or Dropbox, you will need to first upload the file to this API. TempFiles will then return a URL that the others can use to move the file into their respective file stores. Files uploaded here will be deleted after four hours. Be sure to move them using the other APIs within that time frame.

Note: There is a limit on the body size of requests so the file size is limited to under 10 MB. We recommend the use of an alternative cloud storage solution for larger assignments.

Note: If you inadvertently leveraged the OAuth 1 flow for the this API to upload the file attachment, you will receive a status code of 201 (Created) for a properly formatted request. However when you attempt to attach the file resource to a dropbox message or Doc Sharing area, you will receive a 401 status code (Unauthorized) and the file resource will not be uploaded to the corresponding course area. To resolve the issue, you will need to use the supported authentication protocol (OAuth 2) to upload the file resource to the tempfiles API.



Supported Roles and Authentication Protocols

Type Supported Values
Authentication Protocols OAuth 2.0
Valid for Roles (OAuth 2): Professor, Teaching Assistant, Student

API Request

API Endpoints

HTTP Verbs and URIs

POST /tempfiles{.format}
  • Upload the contents of a file to LearningStudio.

Parameters

Name Description Valid Values
{.format} Desired format of response data. See Response Formats. .json , .xml , or Blank

Query String Parameters

Query Parameter Name Description Valid Values
expand You can upload virtually any type of file to LearningStudio. If you upload a compressed archive (e.g., a zip file), you can upload it as is, or use this parameter to have LearningStudio uncompress it into individual files. If set to true, the API will return URLs for the original ZIP and each of the constituent files.

Note: If using this parameter, the Location HTTP Response Header will only contain the location of the compressed archive. You will need to parse the response body to get the locations of the constituent files.

See the example below.

true , false , or Blank

Request Headers

In addition to the standard Authentication header, you will need headers that describe the content you're sending to LearningStudio.

Format

 
Content-Length: {length}
Content-Type: multipart/form-data; boundary={boundaryText}

Parameter Descriptions

Name Description Valid Values
{length} The total length (number of characters) of the request body (see below). Any integer number
{boundaryText} Any arbitrary string that will note the sections in a multipart request body. In this API, there is only one section, so this text is used at the start and end of the body (see below). Any random string

Request Body

Format

--{boundary}
Content-Type: {mimeType}
Content-Disposition: form-data; name="{filename}"; filename="{filenameWithExt}"
 
{fileContents}
--{boundary}--

Parameter Descriptions

Name Description Valid Values
{boundary} Notes the start and end of the multipart submission. Note, the final line of the payload shows two sets of double-dashes. The closing boundary must have the second set of dashes. The same value used in the Content-Type HTTP header (see previous section).
{mimeType} The MIME Type of the file you're uploading, e.g. application/pdf. Valid MIME type
{filename} The name of the file you're uploading, without an extension. Valid file name
{filenameWithExt} The name of the file you're uploading, with its extension. Valid file name
{fileContents} The contents of the file. This need not be encoded. Valid file name

API Response

Response Header

This API returns the standard HTTP Status Codes used by the LearningStudio APIs.

In addition to standard HTTP headers, this API returns a Location containing the URL that will be used by other APIs to move the file. This header serves as a shortcut to parsing the response body. However, if uploading a compressed archive and using the expand query string parameter (see above), the Location header contains only the URL for the original zip file; you will need to parse the response body for the URLs of the constituent files.

Response Body

Format

{
   "tempFiles":[{
      "fileName":"{filename}",
      "token":"{fileId}",
      "fileLocation":"{locatorURL}"
   }]
}

Property Descriptions

Name Description
{filename} Actual file name of the file that was uploaded. For example, "myfile.pdf"
{fileId} A GUID identifying the temporary file in LearningStudio. Generally, you don't need this and can just use the fileLocation in other APIs.
fileLocation A full URL that identifies the temporary file in LearningStudio. You'll use this value in other APIs (i.e., Doc Sharing or Dropbox) to instruct them how to move the file to their respective file stores.

Example: Single File Upload

Request

Endpoint

POST /tempfiles

HTTP Headers (Partial)

X-Authorization: Access_Token access_Token=ABCD|JEOF|12345689|2014-10-22T12%3a23%3a28|0123456ABCDefgh
Content-Length: 176
Content-Type: multipart/form-data; boundary=ABCD1234

Body

--ABCD1234
Content-Type: text/plain
Content-Disposition: form-data; name="mytestfile"; filename="mytestfile.txt"
 
This is some test material for the tempfiles API.
--ABCD1234--

Response

HTTP Headers (Partial)

Location: https://api.learningstudio.com/tempfiles/492jfs0f-ac22-0j9k-8177-949jeof68ea

Body

{
   "tempFiles":[{
      "fileName":"\\mytestfile.txt",
      "token":"40a77d92-bd80-4e2a-8177-949cbaec68ea",
      "fileLocation":"https://api.learningstudio.com/tempfiles/40a77d92-bd80-4e2a-8177-949cbaec68ea"
   }]
}

Example: Compressed File Upload With Expansion

Request

Endpoint

POST /tempfiles?expand=true

HTTP Headers (Partial)

X-Authorization: Access_Token access_Token=ABCD|JEOF|12345689|2014-10-22T12%3a23%3a28|0123456ABCDefgh
Content-Length: 686150
Content-Type: multipart/form-data; boundary=ABCD1234

Body

--ABCD1234
Content-Type: application/zip
Content-Disposition: form-data; name="myphotos"; filename="myphotos.zip"
 
PK—ΩrD'1521427_695162930516867_499235152_n.jpgUX
HT:/)SÛIÕ¥∫uT\Õˆ6ÿhÇwwwkBCǪ{¶q˜F#HpwÓ‹	i†ë‡Ó§õ$axÔùô{gʘœ∑÷7OØÆÛú]Uªv’^UµœZ˚q˘q@†™®¢@APû~Ä«øt.¿„6Œo99Km]-Eu S
Œ!‡	OÌÆn>^∫J≤∆&¶œVhj)Ä@o
ˆˆ¸ÅÚ˙kÒflosºˇîúøAÎ
Wı≤wª„ÄxˇCflˇÅ-ƒ¸§N˛âCmû‚˝O 
...
--ABCD1234--

Response

HTTP Headers (Partial)

Location: https://api.learningstudio.com/tempfiles/40f557af-87d7-420a-afdb-849ad6b09e4c

Body

{
   "tempFiles":[{
       "fileName":"\\myphotos.zip",
       "token":"40f557af-87d7-420a-afdb-849ad6b09e4c",
       "fileLocation":"https://m-api.ecollege.com/tempfiles/40f557af-87d7-420a-afdb-849ad6b09e4c"
    },{
        "fileName":"\\photo1.jpg",
        "token":"7015d228-e6e0-4a1e-97a6-4af53610e599",
        "fileLocation":"https://m-api.ecollege.com/tempfiles/7015d228-e6e0-4a1e-97a6-4af53610e599"
    },{
        "fileName":"\\photo2.jpg",
        "token":"2a7095aa-c9e6-4039-a70c-27186e3d297c",
        "fileLocation":"https://m-api.ecollege.com/tempfiles/2a7095aa-c9e6-4039-a70c-27186e3d297c"
    },{
        "fileName":"\\photo3.jpg",
        "token":"1691548f-20c9-40c4-9f14-7a1919ae716d",
        "fileLocation":"https://m-api.ecollege.com/tempfiles/1691548f-20c9-40c4-9f14-7a1919ae716d"
    }]
}
2499 reads
Always Learning
Pearson