com.cloudinary.Cloudinary Java Examples

The following examples show how to use com.cloudinary.Cloudinary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From Pharmacy-Android with GNU General Public License v3.0 5 votes vote down vote up
public static String getImageLowerUrl(String publicId, @NonNull Cloudinary cloudinary) {


        return cloudinary.url()
                .transformation(getLowerTransformation())
                .format("jpg")
                .generate(publicId);
    }
 
Example #2
Source File: Utils.java    From Pharmacy-Android with GNU General Public License v3.0 5 votes vote down vote up
public static String getThumbUrl(String publicId, @NonNull Cloudinary cloudinary) {

        return cloudinary.url()
                .transformation(getThumbnailTransformation())
                .format("jpg")
                .generate(publicId);
    }
 
Example #3
Source File: OrderManager.java    From Pharmacy-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deletes image on the given id
 * @implNote Run it on other than MainThread
 * @param publicId
 * @return void
 */
public static Observable<Void> deleteImage(String publicId) {
    return Observable.create(subscriber -> {
        try {
            Cloudinary cloudinary = Utils.getCloudinary();
            cloudinary.uploader().destroy(publicId, ObjectUtils.emptyMap());
            Timber.i("Image deleted, id: %s", publicId);
            subscriber.onCompleted();
        } catch (IOException e) {
            Timber.e(e, "Image delete error, id: %s", publicId);
            e.printStackTrace();
            subscriber.onError(e);
        }
    });
}
 
Example #4
Source File: UploaderTest.java    From cloudinary_android with MIT License 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    String url = Utils.cloudinaryUrlFromContext(InstrumentationRegistry.getInstrumentation().getContext());
    cloudinary = new Cloudinary(url);
    if (StringUtils.isBlank(url)) {
        throw new IllegalArgumentException("UploaderTest - No cloudinary url configured");
    }

    if (!url.startsWith("cloudinary://")){
        throw new IllegalArgumentException("UploaderTest - malformed cloudinary url");
    }
}
 
Example #5
Source File: TestUtils.java    From cloudinary_android with MIT License 5 votes vote down vote up
public static AbstractUploaderStrategy replaceWithTimeoutStrategy(Cloudinary cloudinary) throws NoSuchFieldException, IllegalAccessException, IOException {
    return TestUtils.replaceStrategyForIntsance(cloudinary, new AbstractUploaderStrategy() {

        @Override
        public Map callApi(String action, Map<String, Object> params, Map options, Object file, ProgressCallback progressCallback) throws IOException {
            throw new IOException();
        }
    });
}
 
Example #6
Source File: TestUtils.java    From cloudinary_android with MIT License 5 votes vote down vote up
public static AbstractUploaderStrategy replaceStrategyForIntsance(Cloudinary cld, AbstractUploaderStrategy replacement) throws NoSuchFieldException, IllegalAccessException {
    Field uploaderStrategy = Cloudinary.class.getDeclaredField("uploaderStrategy");
    uploaderStrategy.setAccessible(true);
    AbstractUploaderStrategy prev = (AbstractUploaderStrategy) uploaderStrategy.get(cld);
    uploaderStrategy.set(cld, replacement);
    return prev;
}
 
Example #7
Source File: OrderManager.java    From Pharmacy-Android with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Uploads image to cloudinary
     * @param file to upload
     * @return public_id of the uploaded image
     */
    public static Observable<String> uploadImage(File file, String orderId) {
        return Observable.create(subscriber -> {


            Cloudinary cloudinary = new Cloudinary(App.getContext().getResources().getString(R.string.cloudinary_url));
/*            String fileName = file.getName();
            int pos = fileName.lastIndexOf(".");
            if (pos > 0) {
                fileName = fileName.substring(0, pos);
            }*/
            String folderName = "ahanaPharmacy/";

            String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();

            Map context = new HashMap();
            context.put("uid", uid);
            context.put("order_id", orderId);
            context.put("status", "PENDING");

            String tags = "prescription, " + uid + "," + orderId + "," + "PENDING";

            Map options = ObjectUtils.asMap(
              "tags", tags,
            "context", context,
            "folder", folderName,
                    // store image as reduced quality 60%
                    "transformation", new Transformation().quality(60)

            );

            try {
              Map map =  cloudinary.uploader().upload(file, options );
                String publicId = map.get("public_id").toString();
                Log.d("uploadImage", "public_id: " + publicId);
               subscriber.onNext(publicId);
                subscriber.onCompleted();

            } catch (IOException e) {
                Timber.e(e, "Image Upload failed");
                e.printStackTrace();
                subscriber.onError(new Throwable("Error uploading prescription. Make sure you're connected to internet"));
            }

        });
    }
 
Example #8
Source File: DefaultRequestProcessor.java    From cloudinary_android with MIT License 4 votes vote down vote up
private Map doProcess(final String requestId, Context
        appContext, Map<String, Object> options, RequestParams params, Payload payload) throws
        PayloadNotFoundException, IOException, ErrorRetrievingSignatureException {
    Logger.d(TAG, String.format("Starting upload for request %s", requestId));
    Object preparedPayload = payload.prepare(appContext);
    final long actualTotalBytes = payload.getLength(appContext);
    final long offset = params.getLong("offset", 0);
    final int bufferSize;
    final String uploadUniqueId;
    int defaultBufferSize = options.containsKey("chunk_size") ? (int) options.get("chunk_size") : Uploader.BUFFER_SIZE;
    if (offset > 0) {
        // this is a RESUME operation, buffer size needs to be consistent with previous parts:
        bufferSize = params.getInt("original_buffer_size", defaultBufferSize);
        uploadUniqueId = params.getString("original_upload_id", null);
    } else {
        bufferSize = ObjectUtils.asInteger(options.get("chunk_size"), defaultBufferSize);
        uploadUniqueId = new Cloudinary().randomPublicId();
    }

    // if there are no credentials and the request is NOT unsigned - activate the signature provider (if present).
    if (!MediaManager.get().hasCredentials() && !TRUE.equals(options.get("unsigned"))) {
        SignatureProvider signatureProvider = MediaManager.get().getSignatureProvider();
        if (signatureProvider != null) {
            try {
                Signature signature = signatureProvider.provideSignature(options);
                options.put("signature", signature.getSignature());
                options.put("timestamp", signature.getTimestamp());
                options.put("api_key", signature.getApiKey());
            } catch (Exception e) {
                throw new ErrorRetrievingSignatureException("Could not retrieve signature from the given provider: " + signatureProvider.getName(), e);
            }
        }
    }

    final ProcessorCallback processorCallback = new ProcessorCallback(actualTotalBytes, offset, callbackDispatcher, requestId);

    try {
        return MediaManager.get().getCloudinary().uploader().uploadLarge(preparedPayload, options, bufferSize, offset, uploadUniqueId, processorCallback);
    } finally {
        // save data into persisted request params to enable resuming later on
        params.putInt("original_buffer_size", bufferSize);
        params.putLong("offset", processorCallback.bytesUploaded - processorCallback.bytesUploaded % bufferSize);
        params.putString("original_upload_id", uploadUniqueId);
    }
}
 
Example #9
Source File: ResponsiveTest.java    From cloudinary_android with MIT License 4 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    String url = Utils.cloudinaryUrlFromContext(InstrumentationRegistry.getInstrumentation().getContext());
    cloudinary = new Cloudinary(url);
}
 
Example #10
Source File: ResponsiveUrl.java    From cloudinary_android with MIT License 3 votes vote down vote up
/**
 * Create a new responsive url generator instance.
 *
 * @param cloudinary The cloudinary instance to use.
 * @param autoWidth  Specifying true will adjust the image width to the view width
 * @param autoHeight Specifying true will adjust the image height to the view height
 * @param cropMode   Crop mode to use in the transformation. See <a href="https://cloudinary.com/documentation/image_transformation_reference#crop_parameter">here</a>).
 * @param gravity    Gravity to use in the transformation. See <a href="https://cloudinary.com/documentation/image_transformation_reference#gravity_parameter">here</a>).
 */
ResponsiveUrl(@NonNull Cloudinary cloudinary, boolean autoWidth, boolean autoHeight, @Nullable String cropMode, @Nullable String gravity) {
    this.cloudinary = cloudinary;
    this.autoWidth = autoWidth;
    this.autoHeight = autoHeight;
    this.cropMode = cropMode;
    this.gravity = gravity;
}
 
Example #11
Source File: Utils.java    From Pharmacy-Android with GNU General Public License v3.0 2 votes vote down vote up
public static Cloudinary getCloudinary() {

        return new Cloudinary(App.getContext().getString(R.string.cloudinary_url));
    }
 
Example #12
Source File: MediaManager.java    From cloudinary_android with MIT License 2 votes vote down vote up
/**
 * Get an instance of the Cloudinary class for raw operations (not wrapped).
 *
 * @return A Pre-configured {@link com.cloudinary.Cloudinary} instance
 */

public Cloudinary getCloudinary() {
    return cloudinary;
}
 
Example #13
Source File: ResponsiveUrl.java    From cloudinary_android with MIT License 2 votes vote down vote up
/**
 * Build an instance of {@link ResponsiveUrl} pre-configured according to the preset.
 *
 * @param cloudinary Cloudinary instance to use.
 * @return The {@link ResponsiveUrl} instance
 */
public ResponsiveUrl get(Cloudinary cloudinary) {
    return new ResponsiveUrl(cloudinary, autoWidth, autoHeight, cropMode, gravity);
}