简体   繁体   English

java-获取用户选择上传文件的完整路径

[英]java- obtain full path to file selected by a user for upload

I am trying to create a simple screen where the file selected for upload by the user is assigned to a file variable. 我正在尝试创建一个简单的屏幕,其中将用户选择上传的文件分配给文件变量。

Google Data APIs have a class "MediaFileSource" which uses "File" to store a file. Google数据API的类“ MediaFileSource”使用“文件”存储文件。 Given below is code to assign an image file to a MediaFileSource object. 下面给出的是将图像文件分配给MediaFileSource对象的代码。

MediaFileSource myMedia = new MediaFileSource(new File("/home/liz/puppies.jpg"), "image/jpeg");

What I want to do is, ask the user to specify an image for upload, and then assign that image(chosen by the user using my web app) to the MediaFileSource variable. 我想要做的是,要求用户指定要上传的图像,然后将该图像(由用户使用我的Web应用程序选择)分配给MediaFileSource变量。 I just need the full path to that image (which was chosen by the end user) to assign it to a MediaFileSource variable. 我只需要该图像的完整路径(由最终用户选择)即可将其分配给MediaFileSource变量。

What is the best way to do this? 做这个的最好方式是什么? I plan to create the above functionality in a java web application on Google App Engine. 我计划在Google App Engine的Java Web应用程序中创建上述功能。

You can't get the full path on the user machine, only the file name. 您无法在用户计算机上获取完整路径,只能获取文件名。
It's for security reason and its not related to Google App Engine. 这是出于安全原因,与Google App Engine不相关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM