Learn R Programming

MTurkR (version 0.8.0)

GetFileUpload: Get Files Uploaded by Workers

Description

Get the URL for a file uploaded by a worker as part of a QuestionForm HIT, or download the file(s) directly to the working directory.

Usage

GetFileUpload(assignment, questionIdentifier, download = FALSE, 
              open.file.in.browser = FALSE, 
              verbose = getOption('MTurkR.verbose', TRUE), 
              ...)

Arguments

assignment

A character string containing an AssignmentId, or a vector of character strings each containing an AssignmentId.

questionIdentifier

A question identifier for a file upload question, as specified in the question parameter of CreateHIT or in the placeholder of a HIT template created in the RUI.

download

A logical specifying whether the file(s) should be downloaded and saved in the working directory. Default is FALSE.

open.file.in.browser

A logical specifying whether the file should be opened in the user's default web browser.

verbose

Optionally print the results of the API request to the standard output. Default is taken from getOption('MTurkR.verbose', TRUE).

...

Additional arguments passed to request.

Value

A data frame containing the AssignmentId, questionIdenifier, temporary file URL, and an indicator of whether each request was valid.

Details

Note that a FileUploadURL is only valid for 60 seconds (per MTurk documentation), so URLs should either be retrieved one at a time or files should be automatically downloaded to the working directory with the download = TRUE. If browser = TRUE, request is executed in the user's default web browser, whereas if open.file.in.browser = TRUE, the request is executed in R and the file itself is opened in the browser.

If downloaded, files are saved in the local directory with names of the form “QuestionIdentifer_AssignmentId_UploadedFileName.UploadedFileExtension”. One may want to use setwd to move to an appropriate directory before initiating this operation with download = TRUE.

geturls() is an alias.

References

API Reference

Examples

Run this code
# NOT RUN {
a <- GenerateExternalQuestion("http://www.example.com/","400")
hit1 <- 
CreateHIT(title = "Upload a file",
          description = "Upload a file",
          reward = ".10",
          duration = seconds(days=1),
          keywords = "file, upload",
          question = a$string)
ExpireHIT(hit1$HITId)
a <- GetAssignments(hit = hit1$HITId)
f <- GetFileUpload(a, "dictation", download = TRUE)

# cleanup
DisposeHIT(hit1$HITId)
# }

Run the code above in your browser using DataLab