Search in sources :

Example 1 with RemoteFile

use of com.instructure.canvasapi2.models.RemoteFile in project instructure-android by instructure.

the class AnnouncementFragment method formatHTMLWithAttachment.

private void formatHTMLWithAttachment() {
    RemoteFile attachment = mAnnouncement.getAttachments().get(0);
    String html = mAnnouncement.getMessage() + "<p><a href=\"" + attachment.getUrl() + "\" >" + attachment.getFileName() + "</a></p>";
    mAnnouncementWebView.formatHTML(html, mAnnouncement.getTitle());
}
Also used : RemoteFile(com.instructure.canvasapi2.models.RemoteFile)

Example 2 with RemoteFile

use of com.instructure.canvasapi2.models.RemoteFile in project instructure-android by instructure.

the class FileFolderAPI method uploadFileSynchronousNoRedirect.

@WorkerThread
public static /* Used to manually handle the last redirect */
RemoteFile uploadFileSynchronousNoRedirect(@NonNull RestBuilder adapter, String uploadUrl, Map<String, RequestBody> uploadParams, String mimeType, File file) throws IOException {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withDomain(uploadUrl).withPerPageQueryParam(false).build();
    RequestBody fileBody = RequestBody.create(MediaType.parse(mimeType), file);
    Headers headers = adapter.buildNoRedirects(FilesFoldersInterface.class, params).uploadFile(uploadParams, fileBody).execute().headers();
    String redirect = headers.get("Location");
    String newFileUrl = redirect.split("/create_success")[0];
    // POST to the redirect... according to the docs we need to do this to finalize the file upload process
    RemoteFile newFile = adapter.build(FilesFoldersInterface.class, params).postNewlyCreatedFile(redirect).execute().body();
    // We weren't receiving a url in the response from the POST to the redirect - here we grab the full file info as a work around
    FileFolder fileFolder = FileFolderManager.getFileFolderFromURLSynchronous(newFileUrl);
    newFile.setUrl(fileFolder.getUrl());
    newFile.setThumbnailUrl(fileFolder.getThumbnailUrl());
    return newFile;
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) Headers(okhttp3.Headers) FileFolder(com.instructure.canvasapi2.models.FileFolder) UpdateFileFolder(com.instructure.canvasapi2.models.UpdateFileFolder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RemoteFile(com.instructure.canvasapi2.models.RemoteFile) RequestBody(okhttp3.RequestBody) WorkerThread(android.support.annotation.WorkerThread)

Example 3 with RemoteFile

use of com.instructure.canvasapi2.models.RemoteFile in project instructure-android by instructure.

the class FileFolderAPI method uploadFileSynchronous.

@WorkerThread
public static RemoteFile uploadFileSynchronous(@NonNull RestBuilder adapter, String uploadUrl, Map<String, RequestBody> uploadParams, String mimeType, File file) throws IOException {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withDomain(uploadUrl).withPerPageQueryParam(false).build();
    RequestBody fileBody = RequestBody.create(MediaType.parse(mimeType), file);
    return adapter.build(FilesFoldersInterface.class, params).uploadFile(uploadParams, fileBody).execute().body();
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RequestBody(okhttp3.RequestBody) WorkerThread(android.support.annotation.WorkerThread)

Example 4 with RemoteFile

use of com.instructure.canvasapi2.models.RemoteFile in project instructure-android by instructure.

the class UserAPI method uploadUserFileSynchronous.

@WorkerThread
public static RemoteFile uploadUserFileSynchronous(@NonNull RestBuilder adapter, String uploadUrl, Map<String, RequestBody> uploadParams, String mimeType, File file) throws IOException {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withDomain(uploadUrl).withPerPageQueryParam(false).build();
    RequestBody fileBody = RequestBody.create(MediaType.parse(mimeType), file);
    return adapter.build(UsersInterface.class, params).uploadUserFile(uploadParams, fileBody).execute().body();
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RequestBody(okhttp3.RequestBody) WorkerThread(android.support.annotation.WorkerThread)

Example 5 with RemoteFile

use of com.instructure.canvasapi2.models.RemoteFile in project instructure-android by instructure.

the class DiscussionEntryHTMLHelper method getContentHTML.

private static String getContentHTML(DiscussionEntry discussionEntry, String message) {
    if (message == null || message.equals("null")) {
        return "";
    } else {
        StringBuilder html = new StringBuilder();
        html.append("<div class=\"width\">");
        html.append(message);
        for (RemoteFile attachment : discussionEntry.getAttachments()) {
            if (!attachment.isHiddenForUser() && !discussionEntry.isDeleted()) {
                html.append("<div class=\"nowrap\">");
                html.append(String.format("<img class=\"attachment_img\" src=\"" + ATTACHMENT_ICON + "\" /> <a class=\"attachment_link\" href=\"%s\">%s</a>", attachment.getUrl(), attachment.getDisplayName()));
                html.append("</div>");
            }
        }
        html.append("</div>");
        return html.toString();
    }
}
Also used : RemoteFile(com.instructure.canvasapi2.models.RemoteFile)

Aggregations

WorkerThread (android.support.annotation.WorkerThread)3 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)3 RestParams (com.instructure.canvasapi2.builders.RestParams)3 RemoteFile (com.instructure.canvasapi2.models.RemoteFile)3 RequestBody (okhttp3.RequestBody)3 FileFolder (com.instructure.canvasapi2.models.FileFolder)1 UpdateFileFolder (com.instructure.canvasapi2.models.UpdateFileFolder)1 Headers (okhttp3.Headers)1