当前位置: 首页>>代码示例>>Java>>正文


Java TypedFile类代码示例

本文整理汇总了Java中retrofit.mime.TypedFile的典型用法代码示例。如果您正苦于以下问题:Java TypedFile类的具体用法?Java TypedFile怎么用?Java TypedFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TypedFile类属于retrofit.mime包,在下文中一共展示了TypedFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadAvatar

import retrofit.mime.TypedFile; //导入依赖的package包/类
private void uploadAvatar(final String localPath) {
    File file = new File(localPath);
    TalkClient.getInstance().getUploadApi()
            .uploadFile(file.getName(), "image/*", file.length(), new TypedFile("image/*", file))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<FileUploadResponseData>() {
                @Override
                public void call(FileUploadResponseData fileUploadResponseData) {
                    MainApp.IMAGE_LOADER.displayImage("file://" + localPath, ivAvatar);
                    user.setAvatarUrl(fileUploadResponseData.getThumbnailUrl());
                    updateUserInfo();
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {

                }
            });
}
 
开发者ID:jianliaoim,项目名称:talk-android,代码行数:20,代码来源:SetupUserFragment.java

示例2: uploadImage

import retrofit.mime.TypedFile; //导入依赖的package包/类
@Multipart
@Headers({"Content-Type: multipart/form-data",
        "Accept: application/json",
        "Accept-Encoding: gzip, deflate"})
@POST("/api/{userID}/violation/create")
VideoAnswer uploadImage(@Part("photo") TypedFile photo,
                        @EncodedPath("userID") String userID,
                        @Part("latitude") double latitude,
                        @Part("longitude") double longitude);
 
开发者ID:stfalcon-studio,项目名称:patrol-android,代码行数:10,代码来源:PatrulatrulAPI.java

示例3: uploadImage

import retrofit.mime.TypedFile; //导入依赖的package包/类
public void uploadImage(String path) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(API_URL)
            .build();

    UploadService service = restAdapter.create(UploadService.class);

    TypedFile typedFile = new TypedFile("multipart/form-data", new File(path));
    String description = "hello, this is description speaking";

    service.upload(typedFile, description, new Callback<String>() {
        @Override
        public void success(String s, Response response) {
            eventBus.post(new ImageUploadEvent(ImageUploadEvent.Type.COMPLETED, s));
            Log.e("Upload", "success");
        }

        @Override
        public void failure(RetrofitError error) {
            Log.e("Upload", "error");
        }
    });
}
 
开发者ID:alexdao,项目名称:Lollipop,代码行数:24,代码来源:UploadRESTAdapter.java

示例4: run

import retrofit.mime.TypedFile; //导入依赖的package包/类
@Override
protected void run(Context context) throws Throwable {
    String token = AppPrefs.getInstance(context).getSessionToken();

    File file = new File(filePath);
    Dao<User, String> userDao = DatabaseHelper.getInstance(context).getUserDao();
    user = userDao.queryForId(userId);
    user.avatarPath = "file:" + filePath;

    userDao.createOrUpdate(user);

    TypedFile typedFile = new TypedFile("multipart/form-data", file);
    ResponseUser response = NetworkHelper.getNorthstarAPIService()
            .uploadAvatar(token, userId, typedFile);
    user.avatarPath = ResponseUser.getUser(response).avatarPath;
    userDao.createOrUpdate(user);
}
 
开发者ID:DoSomethingArchive,项目名称:LetsDoThis-Android,代码行数:18,代码来源:UploadAvatarTask.java

示例5: analyzeImage

import retrofit.mime.TypedFile; //导入依赖的package包/类
@Override
protected Observable<String> analyzeImage(String imagePath, ImageView imageView) {
    TypedFile imageFile = new TypedFile("image/jpeg", new File(imagePath));

    return ApiCloudSight.getInstance().recognize(imageFile,
            App.getInstance().getTranslationDirection().getFrom().getLanguageCode())
            .delay(RETRY_DELAY_SECONDS, TimeUnit.SECONDS)
            .map(csSendImageResponse -> {
                CSCheckResultResponse checkResultResponse =
                        ApiCloudSight.getInstance().checkResponse(csSendImageResponse.getToken());

                if (checkResultResponse.getStatus().equals(CSCheckResultResponse.STATUS_NOT_COMPLETED)) {
                    throw new RuntimeException("Analyze not completed");
                }

                return checkResultResponse;
            })
            .map(CSCheckResultResponse::getName)
            .retry(MAX_RETRY_COUNT);
}
 
开发者ID:nbsp-team,项目名称:translator-plus,代码行数:21,代码来源:ActivityCloudSightAnalyze.java

示例6: uploadTerms

import retrofit.mime.TypedFile; //导入依赖的package包/类
/**
 * Uploads a translation file. For the moment it only takes terms into account.
 *
 * @param projectId id of the project
 * @param translationFile terms file to upload
 * @param allTags - for the all the imported terms
 * @param newTags - for the terms which aren't already in the project
 * @param obsoleteTags - for the terms which are in the project but not in the imported file and "overwritten_translations"
 * @return UploadDetails
 */
public UploadDetails uploadTerms(String projectId, File translationFile, String[] allTags, String[] newTags, String[] obsoleteTags){
    Map<String, String[]> tags = new HashMap<String, String[]>();
    if(allTags != null) {
        tags.put("all", allTags);
    }
    
    if(newTags != null) {
        tags.put("new", newTags);
    }
    
    if(obsoleteTags != null) {
        tags.put("obsolete", obsoleteTags);
    }
    
    String tagsStr = new Gson().toJson(tags);
    
    TypedFile typedFile = new TypedFile("application/xml", translationFile);
    UploadResponse ur = service.upload("upload", apiKey, projectId, "terms", typedFile, null, "0", tagsStr);
    ApiUtils.checkResponse(ur.response);
    return ur.details;
}
 
开发者ID:lukin0110,项目名称:poeditor-java,代码行数:32,代码来源:POEditorClient.java

示例7: createContent

import retrofit.mime.TypedFile; //导入依赖的package包/类
public PContent createContent() {
	URI uri = null;
	try {
		uri = this.getClass().getResource("/saascms/person.png").toURI();
	} catch (URISyntaxException e) {
	}
	assertNotNull(uri);
	File file = new File(uri);
	assertEquals(true, file.exists());

	PContent pg = new PContent()//
			.setDescription("description")//
			.setTitle("title");

	PContent newContent = contentService.createContent(pg.toMap(), new TypedFile("image/png", file));

	assertNotNull(newContent);
	assertEquals(pg.getTitle(), newContent.getTitle());
	assertEquals(pg.getDescription(), newContent.getDescription());
	assertEquals(file.getName(), newContent.getFileName());
	assertNotEquals(new Long(0), newContent.getFileSize());
	assertNotNull(newContent.getFilePath());
	assertEquals("image/png", newContent.getMimeType());
	
	return newContent;
}
 
开发者ID:phoenix-scholars,项目名称:JPluf,代码行数:27,代码来源:PageServiceTest.java

示例8: controller

import retrofit.mime.TypedFile; //导入依赖的package包/类
@Rubric(
		value="Attempting to submit video data for a non-existant video generates a 404",
		goal="The goal of this evaluation is to ensure that your Spring controller(s) "
				+ "produce a 404 error if a client attempts to submit video data for"
				+ " a video that does not exist.",
		points=10.0,
		reference="This test is derived from the material in these videos: "
		        + "https://class.coursera.org/mobilecloud-001/lecture/207 "
				+ "https://class.coursera.org/mobilecloud-001/lecture/69 "
				+ "https://class.coursera.org/mobilecloud-001/lecture/65"
		)
@Test
public void testAddNonExistantVideosData() throws Exception {
	long nonExistantId = getInvalidVideoId();
	try{
		videoSvc.setVideoData(nonExistantId, new TypedFile(video.getContentType(), testVideoData));
		fail("The client should receive a 404 error code and throw an exception if an invalid"
				+ " video ID is provided in setVideoData()");
	}catch(RetrofitError e){
		assertEquals(404, e.getResponse().getStatus());
	}
}
 
开发者ID:juleswhite,项目名称:mobilecloud-15,代码行数:23,代码来源:AutoGradingTest.java

示例9: testAvatar

import retrofit.mime.TypedFile; //导入依赖的package包/类
@Ignore
@Test
public void testAvatar() {
    File pictureFile = new File("ytsclient/src/integration/resources/logo.png");
    TypedFile picture = new TypedFile("application/octet-stream", pictureFile);
    TypedString appKey = new TypedString(APPLICATION_KEY);
    TypedString userKey = new TypedString(USER_KEY);

    YtsResponse<Profile> response = CLIENT
            .user()
            .picture(appKey, userKey, picture);

    assertNotNull(response);
    assertEquals(YtsStatus.OK, response.status);
    assertNotNull(response.data);
    assertNotNull(response.data.smallImageUrl);
}
 
开发者ID:robertoestivill,项目名称:ytsclient,代码行数:18,代码来源:UserModuleTest.java

示例10: uploadFile

import retrofit.mime.TypedFile; //导入依赖的package包/类
public Subscription uploadFile(final String mimeType, String path, final String tempMsgId, final int duration, final int videoWidth, final int videoHeight) {
    File originFile = new File(path);
    if (originFile.length() <= 0) {
        return null;
    }
    if ("audio/amr".equals(mimeType) && originFile.length() < 100) {
        callback.onUploadFileInvalid(tempMsgId);
        return null;
    }
    TypedFile file = new TypedFile(mimeType, originFile);
    return uploadApi.uploadFile(originFile.getName(), mimeType, originFile.length(), file)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<FileUploadResponseData>() {
                @Override
                public void call(FileUploadResponseData fileUploadResponseData) {
                    if (mimeType.equals("audio/amr")) {
                        fileUploadResponseData.setSpeech(true);
                        fileUploadResponseData.setDuration(duration);
                    } else if (mimeType.equals("video")) {
                        fileUploadResponseData.setWidth(videoWidth);
                        fileUploadResponseData.setHeight(videoHeight);
                        fileUploadResponseData.setDuration(duration);
                    }
                    callback.onUploadFileSuccess(fileUploadResponseData, tempMsgId);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    throwable.printStackTrace();
                    callback.onUploadFileFailed(tempMsgId);
                }
            });
}
 
开发者ID:jianliaoim,项目名称:talk-android,代码行数:34,代码来源:ChatPresenter.java

示例11: testAddNonExistantVideosData

import retrofit.mime.TypedFile; //导入依赖的package包/类
@Test
public void testAddNonExistantVideosData() throws Exception {
	long nonExistantId = getInvalidVideoId();
	try{
		videoSvc.setVideoData(nonExistantId, new TypedFile(video.getContentType(), testVideoData));
		fail("The client should receive a 404 error code and throw an exception if an invalid"
				+ " video ID is provided in setVideoData()");
	}catch(RetrofitError e){
		assertEquals(404, e.getResponse().getStatus());
	}
}
 
开发者ID:juleswhite,项目名称:CSX278,代码行数:12,代码来源:VideoCreationTest.java

示例12: uploadAttachment

import retrofit.mime.TypedFile; //导入依赖的package包/类
private void uploadAttachment() {
    if (!Utils.hasInternet(getActivity())) {
        Toast.makeText(getActivity(), R.string.check_network, Toast.LENGTH_SHORT).show();
        return;
    }
    Context mContext = getActivity();
    mDialog = UiUtils.showProgressDialog(mContext, getString(R.string.creating_attachment));
    TypedFile file = new TypedFile(FileUtils.getMimeType(mFile), mFile);
    Observable<Response> observable = ApiFactory.getService(mContext).createShotAttachments(mShot.id, file);
    observable.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new SucessCallback<Response>(mContext, R.string.create_attachment_success, mDialog), new ErrorCallback(mContext, mDialog));
}
 
开发者ID:goodev,项目名称:droidddle,代码行数:14,代码来源:ShotFragment.java

示例13: createShot

import retrofit.mime.TypedFile; //导入依赖的package包/类
private void createShot() {
    if (mImageFile == null || !mImageFile.exists()) {
        UiUtils.showToast(getActivity(), R.string.shot_image_file_missing);
        return;
    }
    if (mMimeType == null) {
        mMimeType = FileUtils.getMimeType(mImageFile);
    }
    if (!Utils.hasInternet(getActivity())) {
        Toast.makeText(getActivity(), R.string.check_network, Toast.LENGTH_SHORT).show();
        return;
    }
    mDialog = UiUtils.showProgressDialog(getActivity(), getString(R.string.creating));
    String text = mNameView.getText().toString();
    String des = mDescriptionView.getText().toString();
    String tag = mTagsView.getText().toString().trim();
    //TODO set image/png GIF, JPG by file ext name
    TypedFile image = new TypedFile(mMimeType, mImageFile);
    TypedString title = new TypedString(text);
    TypedString description = new TypedString(des);
    TypedString tags = new TypedString(tag);
    Observable<Response> observable = ApiFactory.getService(getActivity()).createShot(image, title, description, tags);
    observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((response) -> {
        bucketCreated(response);
    }, new ErrorCallback(getActivity()));

}
 
开发者ID:goodev,项目名称:droidddle,代码行数:28,代码来源:CreateShotFragment.java

示例14: createLogEvent

import retrofit.mime.TypedFile; //导入依赖的package包/类
/**
 * HockeyApp requires data to be in files uploaded via multipart POST request.
 * Here we create a file containing the log data.
 * @param appId HockeyApp application ID
 * @param storedException Data to place in a log file.
 * @param deleteStoredExceptionCallback Retrofit callback that will delete the exception file
 *                                      after it is uploaded.
 */
@SuppressWarnings("ResultOfMethodCallIgnored")
void createLogEvent(String appId, StoredException storedException,
                            final Callback<Object> deleteStoredExceptionCallback) {
    final File logFile = writeHockeyAppCrashLog(storedException.stackTrace);
    if(logFile != null && logFile.exists()) {
        final TypedFile log = new TypedFile("text/plain", logFile);
        createService().createEvent(
            appId,
            log,
            createLogEventCallback(deleteStoredExceptionCallback, logFile)
        );
    }
}
 
开发者ID:percolate,项目名称:foam,代码行数:22,代码来源:HockeyApp.java

示例15: testCreateLogEvent

import retrofit.mime.TypedFile; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testCreateLogEvent() {
    final Callback mockLogEventCallback = mock(Callback.class);
    final File tempFile = createTempFile();

    HockeyApp hockeyApp = new HockeyApp(null){
        @Override
        File writeHockeyAppCrashLog(String stackTrace) {
            return tempFile;
        }

        @Override
        Callback<Response> createLogEventCallback(Callback<Object> deleteStoredExceptionCallback, File logFile) {
            return mockLogEventCallback;
        }
    };

    StoredException storedException = new StoredException(ServiceType.HOCKEYAPP, "test message", "test threadName", "test\nstack\ntrace");

    HockeyApp.HockeyAppService mockService = mock(HockeyApp.HockeyAppService.class);
    hockeyApp.hockeyAppService = mockService;
    hockeyApp.createLogEvent("UnitTestingAppId", storedException, null);

    ArgumentCaptor<TypedFile> typedFileArgumentCaptor = ArgumentCaptor.forClass(TypedFile.class);
    verify(mockService).createEvent(eq("UnitTestingAppId"), typedFileArgumentCaptor.capture(), eq(mockLogEventCallback));
    assertEquals(tempFile, typedFileArgumentCaptor.getValue().file());
    assertTrue("Failed to clean up temp file [" + tempFile.getAbsolutePath() + "].", tempFile.delete());
}
 
开发者ID:percolate,项目名称:foam,代码行数:30,代码来源:HockeyAppTest.java


注:本文中的retrofit.mime.TypedFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。