2727import org .slf4j .LoggerFactory ;
2828
2929import com .cloudapp .api .CloudAppException ;
30+ import com .cloudapp .api .model .CloudAppProgressListener ;
3031import com .cloudapp .api .model .CloudAppItem ;
3132import com .cloudapp .impl .model .CloudAppItemImpl ;
3233
@@ -162,6 +163,10 @@ public List<CloudAppItem> getItems(int page, int perPage, CloudAppItem.Type type
162163 * @see com.cloudapp.api.CloudAppItems#upload(java.io.File)
163164 */
164165 public CloudAppItem upload (File file ) throws CloudAppException {
166+ return upload ( file , CloudAppProgressListener .NO_OP );
167+ }
168+
169+ public CloudAppItem upload (File file , CloudAppProgressListener listener ) throws CloudAppException {
165170 try {
166171 // Do a GET request so we have the S3 endpoint
167172 HttpGet req = new HttpGet (NEW_ITEM_URL );
@@ -182,7 +187,7 @@ public CloudAppItem upload(File file) throws CloudAppException {
182187 null );
183188 }
184189
185- return uploadToAmazon (json , file );
190+ return uploadToAmazon (json , file , listener );
186191
187192 } catch (ClientProtocolException e ) {
188193 LOGGER .error ("Something went wrong trying to contact the CloudApp API." , e );
@@ -209,7 +214,7 @@ public CloudAppItem upload(File file) throws CloudAppException {
209214 * @throws ParseException
210215 * @throws IOException
211216 */
212- private CloudAppItem uploadToAmazon (JSONObject json , File file ) throws JSONException ,
217+ private CloudAppItem uploadToAmazon (JSONObject json , File file , CloudAppProgressListener listener ) throws JSONException ,
213218 CloudAppException , ParseException , IOException {
214219 JSONObject params = json .getJSONObject ("params" );
215220 MultipartEntity entity = new MultipartEntity (HttpMultipartMode .BROWSER_COMPATIBLE );
@@ -223,7 +228,7 @@ private CloudAppItem uploadToAmazon(JSONObject json, File file) throws JSONExcep
223228
224229 // Add the actual file.
225230 // We have to use the 'file' parameter for the S3 storage.
226- InputStreamBody stream = new CloudAppInputStream (file );
231+ InputStreamBody stream = new CloudAppInputStream (file , listener );
227232 entity .addPart ("file" , stream );
228233
229234 HttpPost uploadRequest = new HttpPost (json .getString ("url" ));
0 commit comments