0
無法找到將文件從HDFS附加到電子郵件MimeBodyPart的方式。 這是我迄今的嘗試。我試圖使用FileDataSource和URLDataSource,但沒有運氣。將文件從HDFS附加到javax.mail電子郵件
val attachmentPart = new MimeBodyPart()
val filePath = "FILE_PATH"
val fileName = s"FILE_NAME_${date}.html"
val fs = FileSystem.get(sctx.hadoopConfiguration)
val fullURL = fs.getFileStatus(new Path(filePath+fileName)).getPath.toUri.toURL
//val fullFilePath = fs.getFileStatus(new Path(filePath+fileName)).getPath.toString
val source = new URLDataSource(fullURL)
//val source = new FileDataSource(fullFilePath)
attachmentPart.setDataHandler(new DataHandler(source))
attachmentPart.setFileName("file name")
我得到的一個URLDataSource的情況下,出現以下錯誤:
Exception in thread "main" java.net.MalformedURLException: unknown protocol: hdfs
嘗試註冊Hadoop的FsUrlStreamHandlerFactory處理 '進口org.apache.hadoop.fs.FsUrlStreamHandlerFactory URL.setURLStreamHandlerFactory(新FsUrlStreamHandlerFactory())' –