URL.createObjectURL()根本不在任何浏览器中工作

时间:2016-12-06 11:02:38

标签: javascript angularjs url

嗨,我在尝试每个解决方案后感到很累,但却无法使其发挥作用。

我的http调用是

event.alarms = alarms;

NSArray *alarms2    = event.alarms;
EKAlarm *alarm2     = [alarms2 objectAtIndex:0];
NSDate  *alarmDate2 = [alarm2 absoluteDate];

NSError *error = nil;
BOOL    result = [eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error];

if (result)
{
   [event refresh];
   NSArray *alarms3    = event.alarms;
   EKAlarm *alarm3     = [alarms3 objectAtIndex:0];
   NSDate  *alarmDate3 = [alarm3 absoluteDate];

   if ((alarmDate3 == nil) || ![alarmDate2 isEqualToDate:alarmDate3])
   {
      [eventStore refreshSourcesIfNecessary];
      event = [eventStore eventWithIdentifier:event.eventIdentifier];
      [event addAlarm:[EKAlarm alarmWithAbsoluteDate:alarmDate2]];
      result = [eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error];
   }
}

并且在此代码的成功中

$http({
  method: 'GET',
  url: API_URL + 'v1/file/' + candidateId + '/download',
  headers: {
    'authToken': AuthService.getToken(),
  },
  responseType: 'arraybuffer'
})
.then(function onSuccess(response) {
  successCallback(response);
},
function onError(response) {
  errorCallback(response);
});

我尝试了webkitURL.createObjectURL(blob),它只适用于chrome,但是URL.createObject根本不起作用。

收到消息 URL.createObjectURL()不是函数()

由于

1 个答案:

答案 0 :(得分:0)

有一些与createObjectURL相关的兼容性问题,您可以在此处看到更多:https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

使用Blobhttps://developer.mozilla.org/en-US/docs/Web/API/BlobBuilder#Browser_compatibility

我有一个类似的问题,这个SO链接帮助我解决了一个问题:Blob constructor browser compatibility

我已复制此功能并进行了一些小改动:

var NewBlob = function(data, datatype)
{
    var out;

    try {
        out = new Blob([data], {type: datatype});
        console.debug("case 1");
    }
    catch (e) {
        window.BlobBuilder = window.BlobBuilder ||
                window.WebKitBlobBuilder ||
                window.MozBlobBuilder ||
                window.MSBlobBuilder;

        if (e.name == 'TypeError' && window.BlobBuilder) {
            var bb = new BlobBuilder();
            bb.append(data);
            out = bb.getBlob(datatype);
            console.debug("case 2");
        }
        else if (e.name == "InvalidStateError") {
            // InvalidStateError (tested on FF13 WinXP)
            out = new Blob([data], {type: datatype});
            console.debug("case 3");
        }
        else {
            // We're screwed, blob constructor unsupported entirely   
            console.debug("Errore");
        }
    }
    return out;
}