buli
2023-07-14 e6068da47c1bef5517c9e5fdc8c726766867ad4e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!-- 该页面实现token上传预览 -->
<apex:page standardController="FileAddress__c" extensions="FilePreviewDownVFController" showHeader="false">
    <head>
        <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
        <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
 
        <script>
            var staticResources = JSON.parse('{!staticResource}');
            var fileKey = '{!fileKey}';
            var fileName = '{!fileName}';
            var type = '{!type}';
            var hostUrl = '{!hostUrl}';
 
            var PARAMS = {};
            PARAMS.fileKey = fileKey; 
            PARAMS.fileName = fileName;
            PARAMS.token = staticResources.token;
            console.log('PARAMS = ' + JSON.stringify(PARAMS));
 
            // if(type == 'preview'){
            //     postAWS(staticResources.queryUrl.split('?')[0]+'V2',PARAMS);
            // }else if(type == 'download'){
            //     postAWS(staticResources.undeleteUrl.split('?')[0]+'V2',PARAMS);
            // }
 
            if(type == 'preview'){
                postAWS(hostUrl + '/api/file/cacheFileKey',PARAMS,'preview');
            }else if(type == 'download'){
                postAWS(hostUrl + '/api/file/cacheFileKey',PARAMS,'download');
            }
            //调用AWS进行预览或下载
            function postAWS(url,PARAMS,preDown){
                //组装表单发送
                // jQuery("body").append("<form></form>");
                // jQuery("body").find("form").attr("action",url);
                // jQuery("body").find("form").attr("method","post");
                // jQuery("body").find("form").attr("display","none");
                // jQuery("body").find("form").attr("target","_self");
                // for (var x in PARAMS) { 
                //     jQuery("body").find("form").append("<input type='text' name='"+x+"' value = '"+PARAMS[x]+"' style='display:none'></input>");
                // }
                // jQuery("body").find("form").submit();
                debugger
                console.log('filekey = ' + PARAMS.fileKey);
                console.log('url = ' + url);
                var cacheType = 0;
                if(preDown == 'preview'){
                    cacheType = 1;
                }else if(preDown == 'download'){
                    cacheType = 2;
                }
                fetch(url, {
                    method: 'POST',
                    body: JSON.stringify({ 'fileKey': PARAMS.fileKey, "fileName": PARAMS.fileName, 'token': PARAMS.token,'cacheType':cacheType }),
                    headers: {
                        'Content-Type': 'application/json',
                        'pi-token': PARAMS.token
                    }
                }).then((data) => {
                    return data.json();
                }).then(result => {
                    console.log(result);
                    if(preDown == 'preview'){
                        window.location.href = hostUrl + '/api/file/previewV3?key=' + result.object;
                    }
                    if(preDown == 'download'){
                        console.log('downloadUrl = ' + hostUrl + '/api/file/downloadV3?key=' + result.object+'&fileName='+PARAMS.fileName);
                        window.location.href = hostUrl + '/api/file/downloadV3?key=' + result.object+'&fileName='+PARAMS.fileName;
                    }
                })
            }
            
        </script>
    </head>
 
    <body style="display : none;">
        <span id="loading" style="display : none;">正在生成,请稍候...</span>
    </body>
</apex:page>