cloudinary java not able to upload image - java

my code is below.I try to upload image into cloudinary through java but not uploaded it shows the below error
Exception in thread "main" java.lang.UnknownError: Can't find
Cloudinary platform adapter
[com.cloudinary.android.UploaderStrategy,com.cloudinary.http42.UploaderStrategy,com.cloudinary.http43.UploaderStrategy]
at com.cloudinary.Cloudinary.loadStrategies(Cloudinary.java:76) at
com.cloudinary.Cloudinary.(Cloudinary.java:91) at
ImageUpload.main(ImageUpload.java:16)
my code is following
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.cloudinary.Cloudinary;
import com.cloudinary.utils.ObjectUtils;
public class ImageUpload {
public static void main(String arg[])throws Exception{
Map config = ObjectUtils.asMap(
"cloud_name", "dq8rshzka",
"api_key", "484362882976754",
"api_secret", "1zwPe6-VfVjj3rueX6zSsfyNyro");
Cloudinary cloudinary = new Cloudinary(config);
Map result = cloudinary.api().resource("sample", ObjectUtils.emptyMap());
}
}

Please open a support ticket and Cloudinary's support team will be happy to assist. Regardless, please note that your account's api_secret should never be revealed. You should go to your account's settings page and generate a new pair of api key and secret.

Try add this to your proguard rules file:
-keep class com.cloudinary.** { *; }

Here is my solution for this issue:
-keep class * extends com.cloudinary.strategies.*
this will only keep the missing classes that the SDK needs and mentioned in this error.

You need to add http cloud library,you can find at http://mvnrepository.com/artifact/com.cloudinary/cloudinary-http44/1.3.0

Since version 1.24.1 of the sdk, this issue is fixed as the sdk add the proguard rules itself. See commit https://github.com/cloudinary/cloudinary_android/commit/c8ce933d4396867a18aeb1511198f2abad065e95

Related

How can I fix the project build path error? I can't import the java.lang.math for a Java 8/9 Calculator app

I am developing a simple calculator application in Java 8/9 in Eclipse. I am working on the power operation (as in "to the power of" used in math). I want to use the Math.power() instead of a for loop. However, I am having trouble importing the java math package into the program. The internet says to add import java.lang.math. When I try to code it in, I receive a notice of "Cannot Perform Operation. This compilation unit is not on the build path of the Java Project". What am I overlooking and/or doing wrong? Please provide suggestions or feedback.
Please note: Yes this is an academic assignment. To make this clear, I am not asking for the coding of the power operation. This issue is specifically about the importing the math package.
power operation (power.java)
package org.eclipse.example.calc.internal.operations;
import org.eclipse.example.calc.BinaryOperation;
// import java.lang.math; produces error
// Binary Power operation
public class Power extends AbstractOperation implements BinaryOperation {
// code removed. not relevant to SOF question.
}
Main (calculator.java)
package org.eclipse.example.calc.internal;
import org.eclipse.example.calc.BinaryOperation;
import org.eclipse.example.calc.Operation;
import org.eclipse.example.calc.Operations;
import org.eclipse.example.calc.UnaryOperation;
import org.eclipse.example.calc.internal.operations.Power;
import org.eclipse.example.calc.internal.operations.Equals;
import org.eclipse.example.calc.internal.operations.Minus;
import org.eclipse.example.calc.internal.operations.Plus;
import org.eclipse.example.calc.internal.operations.Divide;
import org.eclipse.example.calc.internal.operations.Square;
public class Calculator {
private TextProvider textProvider;
private String cmd;
private boolean clearText;
private float value;
public static String NAME = "Simple Calculator";
public Calculator(TextProvider textProvider) {
this.textProvider = textProvider;
setupDefaultOperations();
}
private void setupDefaultOperations() {
new Power();
new Equals();
new Minus();
new Plus();
new Divide();
new Square();
}
....
BTW, I use camel Case normally, but the academic project name everything including file names in standard writing format.
EDIT: After reading a response, I realized I forget to mention this. I can't get any further than typing import java., then the error pop-ups. Then I can't type the rest of the import statement
Image of package hierarchy
Your project is not configured correctly. You have no source dir at all. The src dir should be marked as source dir; right click it and tell eclipse about this, or, as it is a maven project, it's more likely a broken pom. Also, why are you using the org.eclipse package? If you work for SAP, it should be com.sap.

How to use C++ or Java Console Application to operate my Cloud Firestore project?

I use Cloud Firestore to store data for my Android application, then I want to make a supporting tool to operate my Cloud Firestore project easily.(It is too hard and bore for me and my fingers to add more 100 datas in a constant format to Cloud Firestrore by Webpage GUI.)
Therefore, I want to make a support tool to
read CSV file(I know how to do this in C++ or Java)
connect to my Cloud Firestore project
operate(add or erase) data deriving from CSV file.
I read Google Official start up guide "Get started with Cloud Firestore"(https://firebase.google.com/docs/firestore/quickstart#java_1), and did following things.
install gradle
Set User environment variable in following sentence.(the location is the secret json file made by Cloud Firestore Service Account.)
GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
write "build.gradle" as following sentence.
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'Main'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.firebase:firebase-admin:6.11.0'
implementation 'com.google.firebase:firebase-firestore:21.2.1'
}
write following java file.
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.Firestore;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import java.io.*;
//the following two package does not exist, by gradle's compiling.
import com.google.firebase.cloud.*;
import com.google.firebase.firestore.*;
public class Main {
public static void main(String args[]) {
try {
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl("https://rikotenapp2020.firebaseio.com").build();
FirebaseApp.initializeApp(options);
System.out.println("no exception!");
Firestore db = FirestoreClient.getFirestore();
//from my survey, if I erase the rest code(DocumentReference...~println();})
//I can compile it successfully.
DocumentReference ref = db.collection("AppVersion").document("Android");
ApiFuture<DocumentSnapshot> future = ref.get();
DocumentSnapshot document = future.get();
if (document.exists()) {
System.out.println("android app version is " + document.getData());
} else {
System.out.println("No such document!");
}
} catch (IOException e) {
System.out.println("IOException happened!");
}
}
}
I set up "Firestore Admin SDK", was I wrong?
If someone know how to resolve this, I'm very glad to get your valuable advices if you can tell me.
This is my first question, and I'm not native English speaker.Please forgive my hard-understand question.
I resolve it now.
What I should do is doing following official tutorial(https://firebase.google.com/docs/firestore/quickstart).
However, because I use Visual Studio Code to edit java program, and I don't have any plugin to adapt "Auto Import" about external library, I found this situation as a hard problem.
For other people who will come here:
The introduction of Java in tutorial doesn't have careful import sentence.The best and direct way to resolve it is reading official reference(https://googleapis.dev/java/google-cloud-firestore/latest/index.html) and write in your java program with import sentences.
This question is starting from my misunderstanding. I appreciate all people to help me about this problem.

Runtime or class error running JJWT Json Token

I have a little problem. I´ve been trying to use different libraries to produce a json token and now I'm using JJWT from Stormpath. They have tutorials well explained. But my problem is, when I try to run the String method in a "public static void main" method, I get a runtime or class error. In their official website says there is a requeriment that the jackson library must being newer than Version 2.8. So I downloaded such library.
Here my source code:
package org.comunidadIT.proyecto.accesoDatos;
import java.security.Key;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.crypto.MacProvider;
public class ValidarToken {
public String token(){
// We need a signing key, so we'll create one just for this example. Usually
// the key would be read from your application configuration instead.
Key key = MacProvider.generateKey();
String compactJws = Jwts.builder()
.setSubject("Joe")
.signWith(SignatureAlgorithm.HS512, key)
.compact();
return compactJws;
}
public static void main(String args[]){
ValidarToken t= new ValidarToken();
System.out.println(t.token());
}
}
The console show following error message:
Exception in thread "main" java.lang.NoSuchFieldError: USE_DEFAULTS
at com.fasterxml.jackson.annotation.JsonInclude$Value.<clinit>(JsonInclude.java:204)
at com.fasterxml.jackson.databind.cfg.MapperConfig.<clinit>(MapperConfig.java:44)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:549)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:465)
at io.jsonwebtoken.impl.DefaultJwtBuilder.<clinit>(DefaultJwtBuilder.java:42)
at io.jsonwebtoken.Jwts.builder(Jwts.java:116)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.token(ValidarToken.java:16)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.main(ValidarToken.java:27)
Image from maven dependencies where appears to be fine with jackson
Image from the console with erros
As you can see the jackson dependencies appears to be fine.
Also I aatached more libreries to the build-path on reference libraries, but they are outside from the pom.xml.
What do I do wrong?
Thank you
I answer myself so perhaps someone could have the same problem.
I've been with this problem about a month, until I got balls to delete some old libraries located in my project.
The problem appeared to be that I declared a Maven dependecy with jackson 2.8.2 or later and in the 'reference libraries' I had libraries lowers than 1.9, when I removed from my Build-Path the problem was gone. And now I can see the String Token.
This is the picture with the problem solved.
Thank you.

Java HttpServer Error: Access restriction: The type 'HttpServer' is not API

I was trying to do something with the java HttpServer class.
This is the minimal example from the documentation:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpServer;
class MyHandler implements HttpHandler
{
public void handle(HttpExchange t) throws IOException
{
InputStream is = t.getRequestBody();
read(is); // .. read the request body
String response = "This is the response";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
public class Main
{
HttpServer server = HttpServer.create(new InetSocketAddress(8000));
server.createContext("/applications/myapp", new MyHandler());
server.setExecutor(null); // creates a default executor
server.start();
}
But i get this error message:
Description Resource Path Location Type
Access restriction: The type 'HttpServer' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre/lib/rt.jar') Main.java /test/src/test line 7 Java Problem
What does this even mean? According to the Oracle documentation this should work. Or am i getting this wrong?
The error message wants to say that you are accessing code that is not part of the official API for that library. More specifically, com.sun.net.httpserver.HttpServer is a class which is not guaranteed to be included in all Java 8 runtime implementations. Therefore, code using that class may fail in some Java installations.
In order to still be able to use this class, look into the answers to this question: Access restriction on class due to restriction on required library rt.jar?.
Don't think so that you should use Sun's internal packages but still you can try disabling the error :
Go to Project properties -> Java Compiler -> Errors/Warnings -> Deprecated and restricted API
Also this post may help you.
If still the problem remains you can go with Christian Hujer's answer who says Eclipse has a mechanism called access restrictions to prevent you from accidentally using classes which Eclipse thinks are not part of the public API.
Remove the JRE System Library from the build path and add it back.
Select "Add Library" and select the JRE System Library. The default one should work.
BuildPath >> Libraries

Javascript to Java communication using LiveConnect not working

I've been working on a project that requires communication both directions between Java and JavaScript. I have successfully managed to get it working under all browsers in OS X, but I'm now faced with the challenge of getting it to run on Windows under any browser. At the moment it simply doesn't work.
I'm just wondering if there is something special I need to do in order for JavaScript to communicate with Java?
My applet code looks like this:
<applet id='theApplet'
code="com/company/MyApplet.class"
archive="SMyApplet.jar"
height="50" width="900"
mayscript="true" scriptable="yes">
Your browser is ignoring the applet tag.
</applet>
Once the applet has loaded, I then try to call functions on it like this:
alert("Call some java:" + theApplet.testFunc());
And in the firebug console I get the following error:
theApplet.testFunc is not a function
I can confirm that this doesn't work in IE either.
When the page loads, I have the java console open and I can see that the applet is successfully loading and ready to accept calls.
Any help would be greatly appreciated!
Cheers
Update: Here is the stripped down java code exposing the public api that I'm trying to call.
package com.company;
import com.google.gson.Gson;
import java.applet.*;
import java.io.*;
import java.net.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.*;
import netscape.javascript.*;
public class MyApplet extends Applet implements Runnable
{
public void init()
{
JSON = new Gson();
isReadyVar = 0;
workThread = null;
}
public void start()
{
}
public void run()
{
System.out.println("Done");
}
public void stop()
{
}
public void destroy()
{
}
/* Public API */
public int testFunc()
{
return 200;
}
}
Update [SOLVED]:
I figured out what the problem was exactly. Turns out the Gson lib I was using wasn't signed; but my own jar was. Browsers on windows require that all libs are signed; so I packaged Gson in with my java files & signed the lot and it solved the problem! Thanks for everyones help!
I figured out what the problem was exactly. Turns out the Gson lib I was using wasn't signed; but my own jar was. Browsers on windows require that all libs are signed; so I packaged Gson in with my java files & signed the lot and it solved the problem! Thanks for everyones help!
alert("Call some java:" + document.getElementbyId("theApplet").testFunc());
Make sure the testFunc() method is declared as public access.
If that does not work, post the applet code as an SSCCE.
BTW
Incorrect
code="com/company/MyApplet.class"
Correct
code="com.company.MyApplet"
BTW 2
Incorrect
..scriptable="yes">
Correct
..scriptable="true">
Since the applet element is deprecated, I use following code, which works at least in Firefox:
<object id="MyApplet" classid="java:com.example.myapplet"
codetype="application/java" codebase="bin/" height="10" width="10"
</object>

Categories