質問

i am uploading file using upload from then after getting uploaded file i am using Apache tika top extract content,metadata from uploaded file and applying but some error is coming

have a look of my playframework controller code :

public static Result upload() {
        MultipartFormData body = request().body().asMultipartFormData();
        FilePart picture = body.getFile("doc");
        if (picture != null) {

            String fileName = picture.getFilename();
            int eof = fileName.lastIndexOf('.');
            String ext = fileName.substring(eof + 1);
            
            file = picture.getFile();
            
            InputStream is;
            try {
                is = new FileInputStream(file);
            } catch (FileNotFoundException e) {
                
                e.printStackTrace();
            }
            Parser ps=new AutoDetectParser();
            
            BodyContentHandler bch=new BodyContentHandler();
            
            Metadata metadata=new Metadata();
            
            try {
                ps.parse(is, bch, metadata, new ParseContext());
            } catch (IOException | SAXException | TikaException e) {
                
                e.printStackTrace();
            }
            
            String sw=bch.toString();

            
            return ok(sw+" entity extracted and saved" + ext);
      }else {
        flash("error", "Missing file");
        return redirect(routes.Application.index());
    }

but when i am running this web application i am using commands:

rahul@inext:~/playframwrk apps/EntWebPrj$ play
        [info] Loading project definition from /home/rahul/playframwrk apps/EntWebPrj/project
[info] Set current project to EntWebPrj (in build file:/home/rahul/playframwrk%20apps/EntWebPrj/)
       _            _
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/
play! 2.1.2 (using Java 1.7.0_25 and Scala 2.10.0), http://www.playframework.org
> Type "help play" or "license" for more information.
> Type "exit" or use Ctrl+D to leave this console.
[EntWebPrj] $ ~run

it is giving error :

if you want to see full error then full error

and some of error is :

sbt.PlayExceptions$CompilationException: Compilation error[error: package org.apache.tika.exception does not exist]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:349) ~[na:na]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15$$anonfun$apply$16.apply(PlayReloader.scala:349) ~[na:na]
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:349) ~[na:na]
    at sbt.PlayReloader$$anon$2$$anonfun$reload$2$$anonfun$apply$15.apply(PlayReloader.scala:346) ~[na:na]
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:na]
[warn] play - No application found at invoker init

i added tika jar file.

Give me some idea to fix this issue.

役に立ちましたか?

解決

Adding a dependency to Playframework can be done in two ways :

  1. Unmanaged dependencies : directly add the jar in a /lib folder at the root of your project and restart your play application.

  2. Managed dependencies : Add the jar to your build.sbt file as in the following example :

    val appDependencies = Seq(
        jdbc, cache,
        "org.apache.tika" % "tika" % "0.3"
    )
    

他のヒント

I think you need to also add the tika-parsers-X.Y.jar file (where X.Y is the version e.g., 1.4).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top