我正在尝试将图像从本地系统上传到Azure中的Blob存储。 我要获取图像名称,但是如何获取所选图像的完整路径?
这就是我所做的:
class Uploadfile @Inject() (implicit val messagesApi: MessagesApi, ec: ExecutionContext) extends Controller with i18n.I18nSupport
{
var path="";
val dbConfig = Database.forURL("jdbc:mysql://localhost:3306/equineapp?user=root&password=123456", driver = "com.mysql.jdbc.Driver")
def upload(HorseId : Int) = Action(parse.multipartFormData) { request =>
request.body.file("picture").map { picture =>
val filename = Paths.get(picture.filename).getFileName /// from here i am geeting Image name
var connString="DefaultEndpointsProtocol=https;AccountName=XXXXXXXXXXXXX;AccountKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==;EndpointSuffix=core.windows.net";
val account = CloudStorageAccount.parse(connString)
val serviceClient = account.createCloudBlobClient
// Container name must be lower case.
val container = serviceClient.getContainerReference("myimages")
container.createIfNotExists
// Upload an image file.s
val blob = container.getBlockBlobReference(filename.toString())
//var path =filename.getRoot
//def absolutePath: String = new File(filename).getAbsolutePath();
var pathimage=filename.getFileSystem//// how to get full path of selected Image
val sourceFile = new File(pathimage.toString())
blob.upload(new FileInputStream(sourceFile), sourceFile.length)
// val setup1 = sql"call horseimagepath ($HorseId, $path);".as[(String)]
// val res = Await.result(dbConfig.run(setup1), 1000 seconds)
Ok("File uploaded"+filename+ sourceFile)
}.getOrElse {
Redirect(routes.HomeController.index()).flashing(
"error" -> "Missing file")
}
}
}
如果我对图像的完整路径进行硬编码,那么我没有得到任何例外,但是如何动态获取图像的完整路径?