|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | +<html xmlns="http://www.w3.org/1999/xhtml" > |
| 3 | +<head> |
| 4 | +<title>Demo SDK Java Upload</title> |
| 5 | +<style> |
| 6 | +#upload_container #link_upload_html { |
| 7 | + display: block; |
| 8 | + padding-top: 5px; |
| 9 | +} |
| 10 | +#upload_container #swfu_files { |
| 11 | + padding-top: 20px; |
| 12 | +} |
| 13 | +#upload_container #swfu_files .swfu_file { |
| 14 | + border-bottom: 1px dotted #cccccc; |
| 15 | + padding: 10px; |
| 16 | +} |
| 17 | +#upload_container #swfu_files .swfu_file .file_infos { |
| 18 | + font-size: 10px; |
| 19 | + line-height: 10px; |
| 20 | + padding-bottom: 10px; |
| 21 | +} |
| 22 | +#upload_container #swfu_files .swfu_file .file_infos .tool { |
| 23 | + margin-right: 5px; |
| 24 | +} |
| 25 | +#upload_container #swfu_files .swfu_file .file_infos .file_status { |
| 26 | + color: grey; |
| 27 | +} |
| 28 | +#upload_container #swfu_files .swfu_file .file_infos .file_status.error { |
| 29 | + color: red; |
| 30 | +} |
| 31 | +#upload_container #swfu_files .swfu_file .file_infos .file_status.done { |
| 32 | + color: #2fab09; |
| 33 | +} |
| 34 | +#upload_container #swfu_files .swfu_file .file_progressbar_container { |
| 35 | + -moz-border-radius: 6px; |
| 36 | + -webkit-border-radius: 6px; |
| 37 | + -o-border-radius: 6px; |
| 38 | + -ms-border-radius: 6px; |
| 39 | + -khtml-border-radius: 6px; |
| 40 | + border-radius: 6px; |
| 41 | + background-color: white; |
| 42 | + border: 1px solid #cccccc; |
| 43 | + height: 10px; |
| 44 | + padding: 1px; |
| 45 | +} |
| 46 | +#upload_container #swfu_files .swfu_file .file_progressbar_container .file_progressbar { |
| 47 | + -moz-border-radius: 5px; |
| 48 | + -webkit-border-radius: 5px; |
| 49 | + -o-border-radius: 5px; |
| 50 | + -ms-border-radius: 5px; |
| 51 | + -khtml-border-radius: 5px; |
| 52 | + border-radius: 5px; |
| 53 | + background-color: #8398ab; |
| 54 | + height: 10px; |
| 55 | + width: 0px; |
| 56 | +} |
| 57 | +#upload_container #swfu_files .swfu_file .file_progressbar_container .file_progressbar.error { |
| 58 | + background-color: #ffafae; |
| 59 | +} |
| 60 | +</style> |
| 61 | +<%@ page import="com.dmcloud.*"%> |
| 62 | +<%@ page import="java.net.InetAddress"%> |
| 63 | +<% |
| 64 | +String user_id = "YOUR USER ID"; |
| 65 | +String api_key = "YOUR API KEY"; |
| 66 | +String redirect_url = "http://" + InetAddress.getLocalHost().getHostName() + "/examples/MediaCreate.jsp"; |
| 67 | +
|
| 68 | +CloudKey_Media media = new CloudKey_Media(user_id, api_key); |
| 69 | +DCObject result = media.upload(true, true, redirect_url); |
| 70 | +String status_url = result.pull("status"); |
| 71 | +String upload_url = result.pull("url"); |
| 72 | +%> |
| 73 | +<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> |
| 74 | +<script type="text/javascript"> |
| 75 | + var upload_html_interval; |
| 76 | + $(document).ready(function() |
| 77 | + { |
| 78 | + $('#upload_html_form').submit(function() { |
| 79 | + // Build progress bar |
| 80 | + $('#swfu_files').append( |
| 81 | + '<div class="swfu_file" id="file_progress">'+ |
| 82 | + '<div class="file_title">' + $('#upload_file').val() + '</div>'+ |
| 83 | + '<div class="file_infos">'+ |
| 84 | + '<div class="file_size float_left"></div>'+ |
| 85 | + '<div class="float_right"><span class="file_status">initializing</span></div>'+ |
| 86 | + '<div class="clear"></div>'+ |
| 87 | + '</div>'+ |
| 88 | + '<div class="file_progressbar_container">'+ |
| 89 | + '<div class="file_progressbar"></div>'+ |
| 90 | + '</div>'+ |
| 91 | + '</div>'); |
| 92 | +
|
| 93 | + // Ajax Poll for upload progress data |
| 94 | + upload_html_interval = setInterval(function() { |
| 95 | + $.getJSON('<% out.write(status_url); %>', function(upload) { |
| 96 | + var percent = 0; |
| 97 | + var received = 0; |
| 98 | + var size = 0; |
| 99 | +
|
| 100 | + if (typeof(upload) == 'object') |
| 101 | + { |
| 102 | + if (typeof(upload.state) == 'string' && upload.state != 'notfound') |
| 103 | + { |
| 104 | + $('#file_progress .file_status').html(upload.state); |
| 105 | +
|
| 106 | + if (upload.state == 'uploading') |
| 107 | + { |
| 108 | + if (typeof(upload.received) != 'undefined' && typeof(upload.size) != 'undefined') |
| 109 | + { |
| 110 | + percent = (upload.received / upload.size) * 100; |
| 111 | + percent = Math.round(percent * 10) / 10; |
| 112 | + received = upload.received / (1048576); // 1024 * 1024 = 1048576 |
| 113 | + received = Math.round(received * 10) / 10; |
| 114 | + size = upload.size / (1048576); |
| 115 | + size = Math.round(size * 10) / 10; |
| 116 | +
|
| 117 | + $('#file_progress .file_size').html(received+'MB of '+size+'MB'); |
| 118 | + $('#file_progress .file_status').html(percent+'%'); |
| 119 | + $('#file_progress .file_progressbar').css({ |
| 120 | + width: percent+'%' |
| 121 | + }); |
| 122 | +
|
| 123 | + if (received == size) { |
| 124 | + $('#file_progress .file_size').html(''); |
| 125 | + $('#file_progress .file_progressbar').css({ width: '100%' }); |
| 126 | + $('#file_progress .file_status').html('Success'); |
| 127 | + clearInterval(upload_html_interval); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + else |
| 132 | + { |
| 133 | + $('#file_progress .file_size').html(''); |
| 134 | + $('#file_progress .file_progressbar').css({ width: '100%' }); |
| 135 | + $('#file_progress .file_status').html('Success'); |
| 136 | + clearInterval(upload_html_interval); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + }); |
| 141 | + }, 300); |
| 142 | + return true; |
| 143 | + }); |
| 144 | + }); |
| 145 | +</script> |
| 146 | +</head> |
| 147 | +<body> |
| 148 | +<div id="upload_container"> |
| 149 | + <form id="upload_html_form" target="uploadframe" class="form" action="<% out.write(upload_url); %>" method="post" enctype="multipart/form-data"> |
| 150 | + <div class="field_wrapper"> |
| 151 | + <input id="upload_file" type="file" accept="video/*" class="required input_file" name="file"> |
| 152 | + </div> |
| 153 | + <input id="upload_submit" type="submit" name="submit" class="button large input_submit" value="Upload file"> |
| 154 | + <div><iframe id="uploadframe" name="uploadframe" width="0" height="0" frameborder="0" border="0" src="about:blank"></iframe></div> |
| 155 | + </form> |
| 156 | + <div id="swfu_files"></div> |
| 157 | +</div> |
| 158 | + |
| 159 | +</body> |
| 160 | +</html> |
| 161 | + |
0 commit comments