Code Monkey home page Code Monkey logo

docs-integration-sdk-java's People

Contributors

aleksandrfedorov97 avatar linneys avatar ovchinnikova-natalya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docs-integration-sdk-java's Issues

Question: Is it possible to use the convert service by passing the stream of the file instead of a url to download it from ?

Sorry I must be really stupid can you give me an example on how to use convertService ? I don't quite understand how to set the stream/byte array/file to convert in the call.

I wanted to avoid having onlyoffice download the file from a url and pass the file stream directly to it. Is this possible ?

Here my full example:

private void transformWithSDK(final String sourceMimetype, final String targetMimetype, final Map<String, String> parameters,
    		final File sourceFile, final File targetFile, TransformManager transformManager) throws Exception
    {
    	logger.info("START TRANSFORMER SDK '"+this.getClass().getSimpleName());
    	String extensionSource = FilenameUtils.getExtension(sourceFile.getName());
    	String extensionTarget = FilenameUtils.getExtension(targetFile.getName());
    	String srcType = extensionSource;
    	String outType = extensionTarget;

    	String url = urlManager.getInnerDocumentServerUrl();
    	Security security = Security.builder()
    			.key(settingsManager.getSecurityKey())
    			.header(settingsManager.getSecurityHeader())
    			.prefix(settingsManager.getSecurityPrefix())
    			.build();

    	HttpClientSettings httpClientSettings = HttpClientSettings.builder()
    			.ignoreSSLCertificate(settingsManager.isIgnoreSSLCertificate())
    			.build();

    	String convertServiceUrl = settingsManager.getDocsIntegrationSdkProperties()
    			.getDocumentServer()
    			.getConvertService()
    			.getUrl();

    	ConvertRequest convertRequest = ConvertRequest.builder()
    			.async(false)
    			.filetype(srcType) // txt
    			.outputtype(outType) // docx
    			.key(new SimpleDateFormat("MMddyyyyHHmmss").format(new Date()))
    			.url(sourceFile.toURI().toURL().toString()) // ????? I MUS CREATE A GET SERVICE FOR ONLYOFFICE ???
    			.build();

    	requestManager.executePostRequest(
    			urlManager.sanitizeUrl(url) + convertServiceUrl,
    			convertRequest,
    			security,
    			httpClientSettings,
    			new RequestManager.Callback< ValidationResult>() {
    				public ValidationResult doWork(final Object response) throws Exception {
    					String content = IOUtils.toString(((HttpEntity) response).getContent(), "utf-8").trim();
    					JSONObject result = new JSONObject(content);

    					if (result.has("error")) {
    						Integer errorCode = result.getInt("error");

    						return ValidationResult.builder()
    								.status(Status.FAILED)
    								.error(ConvertResponse.Error.valueOfCode(errorCode))
    								.build();
    					}

    					String fileUrl = result.getString("fileUrl");

    					return requestManager.executeGetRequest(
    							fileUrl,
    							httpClientSettings,
    							new RequestManager.Callback<ValidationResult>() {
    								@Override
    								public ValidationResult doWork(final Object response) throws IOException {
    									byte[] bytes = EntityUtils.toByteArray((HttpEntity) response);
    									if (bytes.length > 0) {
    										
    										FileUtils.writeByteArrayToFile(targetFile, bytes);
    										
    										return ValidationResult.builder()
    												.status(Status.SUCCESS)
    												.build();
    									} else {
    										return ValidationResult.builder()
    												.status(Status.FAILED)
    												.error(CommonResponse.Error.DOWNLOAD_RESULT)
    												.build();
    									}
    								}
    							});

    				}
    			});

    	logger.info("END TRANSFORMER SDK '"+this.getClass().getSimpleName());
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.