U-SQL设置输出文件的内容类型

时间:2019-01-09 08:45:13

标签: content-type azure-data-lake u-sql

我为U-SQL查询创建了自定义输出程序,并将其用于图像数据的输出binary []。 但是图像的内容类型是错误的,我尝试更改自定义输出程序中的逻辑,但不适用于我,它将内容类型设置为“ text / plain; charset = utf-8”

那么,有没有办法为自定义输出程序或U-SQL脚本设置内容类型?

下面的C#代码是用于保存图像数据的自定义输出器。

using Microsoft.Analytics.Interfaces;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;    
namespace ImageAssemblies
{
    [SqlUserDefinedExtractor(AtomicFileProcessing = true)]
    public class ImageOutputter : IOutputter
    {
        public override void Output(IRow input, IUnstructuredWriter output)
        {
            var obj = input.Get<object>(0);
            byte[] imageArray = (byte[])obj;
            using (MemoryStream ms = new MemoryStream(imageArray))
            {
                var image = Image.FromStream(ms);
                image.Save(output.BaseStream, ImageFormat.Gif);                
            }
        }
    }
}

以下用于输出图像文件的U-SQL脚本。

USE DATABASE [test];
REFERENCE ASSEMBLY [ImageAssemblies];
SET @@FeaturePreviews = "DataPartitionedOutput:on";

DECLARE @OutputPath string = @"wasb://thumbnail@xxxxxxxxxx.blob.core.windows.net/{FileName}.gif";

@image_out =
    SELECT ImageAssemblies.ImageOps.scaleImageTo(ImgData, 480, 480) AS thumbnail_image,
           FileName + "_480" AS FileName
    FROM dbo.ThumbnailImages;

OUTPUT @image_out
TO @OutputPath
USING new ImageAssemblies.ImageOutputter();

Wrong content type output image

0 个答案:

没有答案